Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why won't source function work in R Markdown?

More of a conceptual question than a strictly coding one. I have an .R script dedicated to importing and generally cleaning my data. I have several different .Rmd scripts that use the data from the general cleaning .R script to run their specific analyses. I would like to be able to source("DataCleaning.R") at the beginning of each of the .Rmd scripts, that way I could reduce redundancy, but I’m getting this error:

'Pulling' is not recognized as an internal or external command,
operable program or batch file.

I could fix this problem by exporting and importing a .csv, but I’m kind of confused why source() won’t work. I’ve tried it on a few computers now. Works fine in .R but not .Rmd. Would have sworn I’ve used it in .Rmd in the past. I reread the documentation on it. I couldn’t find anyone else reporting this exact error message, but I’m trying to find the file containing the code to take a closer look at ‘Pulling’.

QUESTION:

Does source not work in .Rmd, or is this a unique case?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes source does work in .Rmd. Here’s a reproducible example to prove it:

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
fname = tempfile()
writeLines('print("hello")', fname)
```

```{r}
source(fname)
```

enter image description here

The error you are getting must be caused by the content of your external file.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading