Reputation: 28274
I wonder whether I can use knitr
markdown to just create a report on the fly with objects stemming from my current workspace. Reproducibility is not the issue here. I also read this very fine thread here.
But still I get an error message complaining that the particular object could not be found.
1) Suppose I open a fresh markdown document and save it.
2) write a chunk that refers to some lm
object in my workspace. call summary(mylmobject)
3) knitr it.
Unfortunately the report is generated but the regression output cannot be shown because the object could not be found. Note, it works in general if i just save the object to .Rdata and then load it directly from the markdown file.
Is there a way to use objects in R markdown that are in the current workspace? This would be really nice to show non R people some output while still working.
Upvotes: 26
Views: 33197
Reputation: 586
As Julien Colomb commented, I've found the best thing to do in this situation is to save the large objects and then load them explicitly while I'm tailoring the markdown. This is a must if your data is coming through an ODBC and you don't want to run the entire queries repeatedly as you tinker with fonts and themes.
Upvotes: 0
Reputation: 759
The Markdownreports package is exactly designed for parsing a markdown document on the fly.
Upvotes: 1
Reputation: 30174
RStudio opens a new R session to knit()
your R Markdown file, so the objects in your current working space will not be available to that session (they are two separate sessions). Two solutions:
library(knitr); knit('your_file.Rmd')
(or knit2html()
if you want HTML output in one step, or rmarkdown::render()
if you are using R Markdown v2)Upvotes: 36
Reputation: 5305
Might be easier to save you data from your other session using:
save.image("C:/Users/Desktop/example_candelete.RData")
and then load it into your MD file:
load("C:/Users/Desktop/example_candelete.RData")
Upvotes: 29