M. Beausoleil M. Beausoleil - 4 months ago 11
Markdown Question

Seeing the content of a script sourced in a Markdown document (RStudio)

I just want to print the content of an R script sourced in another location.

```{r Model}
source("~/Desktop/model_sim_simple_that_I_want_to_show.R")
```


But this is just sourcing the script and not showing it. Is there a way to do this?

Answer

Sure, just read the lines and then write them back out:

```{r Model, comment=NA}
cat(paste(readLines("~/Desktop/model_sim_simple_that_I_want_to_show.R), collapse="\n"))
```
Comments