I've been writing text separate from my code.
The datasets that I use are large, so I'm not sure about copypasting from my .R file to .Rmd.
Is there some way to add the output (plots, tables...) from my .R file into the .Rmd?
I've been writing text separate from my code.
The datasets that I use are large, so I'm not sure about copypasting from my .R file to .Rmd.
Is there some way to add the output (plots, tables...) from my .R file into the .Rmd?
One style of rmarkdown is to create all the objects to be treated in an R
script then bring them into namespace in the setup chunk individually, through readRDS
or similar or sourcing the whole script. It will depend a lot on the specific script and goals of the rmarkdown presentation, but most often I find myself doing a mix where I do the extract-transform-load in the script and all the plots and tables in Rmd using objects from the script. If I'm confident that the objects won't be changing , I'll use Rds
, otherwise on-the-fly.
Some resources about leveraging R files for Rmd report:
You can create a report from an R file if that is convenient for you
3.3 Render an R script to a report | R Markdown Cookbook
You can read an external script as a chunk in your Rmd document
16.2 Read external scripts into a chunk | R Markdown Cookbook
You can add special comment in your script so that you can read the script wtih labels to then use pieces in several chunks in your document. More powerful than the above
16.3 Read multiple code chunks from an external script (*) | R Markdown Cookbook
One of this could be helpful for your usage
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.