Generating view of cache object in Markdown docume

2019-03-05 10:31发布

问题:

I cannot show object in markdown document that are objects generated in different R script(within the same session). I would like to point out that I am newbie to markdown. So the code is as follows(''' are added before and after):

{r eval=TRUE, echo=FALSE} head(output_by_size,10) # 1st line summary(cars) # 2nd line dim(iris) # 3rd line

when I comment line 2nd and 3rd the following error is generated: Error in head(output_by_size, 10) : object 'output_by_size' not found Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> head

When 1st line is commented, lines 2nd and 3rd work as expected. Output_by_size is just simple data frame object. Could you please help me out?

回答1:

There are 2 ways to load the data "output_by_size" to your .RMD file:

  1. Don't knit your file with the Rstudio "knit" button, save your RMD file and then use the console:

    library(knitr) 
    knit('your_file.Rmd')
    

    This will take your recent environment into account and the error should be gone.

  2. Store your "output_by_size" as "output_by_size.RData" and load it manually in your RMD file

    ```{r load myData, include=FALSE}
    load("output_by_size.RData")
    ```
    

    If you do it this way you can use the "knit" button from RStudio.

I hope one of this ways is a good solution for you.