Generating view of cache object in Markdown document in R

被刻印的时光 ゝ 提交于 2019-12-20 06:24:32

问题


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.



来源:https://stackoverflow.com/questions/40132675/generating-view-of-cache-object-in-markdown-document-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!