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?
>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)
```
The error you are getting must be caused by the content of your external file.
