本文介绍了如何解决R Markdown(Knit)“'closure'is notsubtabletable'"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试首次使用RMarkdown(Knit)生成pdf.默认文件(文件">新文件">"R Markdown")运行良好,编译后会显示生成的pdf.例如,运行以下代码,

I am trying to use RMarkdown (Knit) for the first time to produce pdf. The default file (File > New File > R Markdown) works well, it shows the generated pdf when compiled. For example, the following code runs,

```{r cars}
summary(cars)
```

但是,如果我只是用"myData"换车,它就不会编译并显示,

However, if I just change cars with "myData," it does not compile and shows,

Error in object[[i]] : object of type 'closure' is not subsettable
Calls: <Anonymous> ... withVisible -> eval -> eval -> summary -> summary.default
Execution halted

我在全局环境中加载了"myData",并且可以在原始R脚本中执行其他操作.有人可以提供一些指南吗?非常感谢您的宝贵时间.

I have "myData" loaded in the global-environment and can do other operations in original R script. Can someone please provide some guideline. Thank you very much for your time.

推荐答案

运行Rmarkdown文件会启动一个新的R会话.

Running an Rmarkdown file starts a new R session.

在新会话中,您可以加载存储在data包中的data.frame,但是必须从Rmarkdown文档中加载其他数据集.

Within the new session, you can load the data.frames that are stored in the data package, but other datasets must be loaded from within the Rmarkdown document.

要使myData出现在Rmarkdown文档中,

To get myData to show up in your Rmarkdown document,

  1. 在当前R会话中使用save将文件保存在某处
  2. 然后在Rmarkdown文档中,使用load打开数据集
  1. save the file somewhere with save in your current R session
  2. then in your Rmarkdown document, use load to open up the data set

因此,在您当前的R会话中:

So, in your current R session:

save(myData, file="<path>/myData.Rdata")

并在您的Rmarkdown文件中:

and in your Rmarkdown file:

```{r myDataSummary}
load("<path>/myData.Rdata")
summary(myData)
```

如果您的数据存储为文本文件,并且您不想存储单独的.R文件,请直接在Rmarkdown文件中使用read.csv或friend.

If your data is stored as a text file, and you don't wish to store a separate .R file, use read.csv or friend directly within your Rmarkdown file.

```{r myDataSummary}
myData <- read.csv("<path>/myCSV.csv")
summary(myData)
```

这篇关于如何解决R Markdown(Knit)“'closure'is notsubtabletable'"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 23:13