0

I have a .Rmd file called f1.Rmd (containing a mix of text and R chunks) and an R script called f2.R.

I would like to insert a set of R instructions in f2.R that would execute all the R chunks contained in f1.Rmd, in such a way that all variables created in f1.Rmd would be created in my current R session if I source f2.R (similarly to what happens when clicking on "Run" -> "Run all chunks below from the Rstudio menu").

Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36

1 Answers1

0

If you render the f1.Rmd file from your current environment, this should happen. You can use rmarkdown::render() from the console or a .R script. This will create all the variables in your current environment. It will also have the side effect of making the document.

When you use the knit button in RStudio, this launches the render in a new r session as a background process.

See also the envir option for render.

See also this answer for other options. knitr: run all chunks in an Rmarkdown document

It also depends what your .Rmd is doing.

alice m w
  • 151
  • 6