1 | initial version |
To source an R Markdown file using source('myfile.r')
, you need to first knit the R Markdown file to generate an HTML, PDF, or Word document. Then, in your R console or script, you can use the source()
function to run the R code in the knitted HTML, PDF, or Word output file. Here are the steps:
source()
function and pass the file path of the output file as the argument. For example, source("C:/Users/Username/MyOutputFile.html")
.Note: sourcing an R Markdown file is not the typical use case for R Markdown, which is designed for reproducible research and reporting. Instead, you may want to consider breaking your R code into smaller functions that you can source as needed, or creating a package with your R functions.