在R中的Markdown文档中生成缓存对象的视图 [英] Generating view of cache object in Markdown document in R

查看:147
本文介绍了在R中的Markdown文档中生成缓存对象的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在降价文档中显示由不同R脚本(在同一会话中)生成的对象.我想指出,我是Markdown的新手.因此代码如下(在前后添加''):

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

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

当我在第2和第3行添加注释时,会产生以下错误: 头错误(output_by_size,10):找不到对象'output_by_size' 调用:... withCallingHandlers-> withVisible-> eval-> eval-> head

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

注释第一行时,第二行和第三行按预期工作. Output_by_size只是简单的数据框对象.你能帮我吗?

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?

推荐答案

有两种方法可以将数据"output_by_size"加载到您的.RMD文件中:

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

  1. 不要使用Rstudio的编织"按钮来编织文件,保存RMD文件,然后使用控制台:

  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.

将"output_by_size"存储为"output_by_size.RData",并将其手动加载到RMD文件中

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")
```

如果采用这种方式,则可以使用RStudio中的编织"按钮.

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.

这篇关于在R中的Markdown文档中生成缓存对象的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆