【发布时间】:2013-03-08 06:04:40
【问题描述】:
我正在运行 R 版本 2.15.3 和 RStudio 版本 0.97.312。我有一个脚本可以从各种来源读取我的数据并创建多个 data.tables。然后我有另一个 r 脚本,它使用在第一个脚本中创建的 data.tables。我想把第二个脚本变成一个 R markdown 脚本,这样分析的结果就可以作为报告输出。
我不知道read_chunk 的用途,而不是source。我的read_chunk 不工作,但source 工作。无论哪种情况,我都看不到 RStudio 工作区面板中的对象。
请解释read_chunk和source的区别?我为什么要使用其中一个?为什么我的 .Rmd 脚本不起作用
这是一个非常简单的示例
它不起作用。我收到以下消息
错误:找不到对象“z”
两个简单的文件...
测试 rmd.R 的源代码
x <- 1:10
y <- 3:4
z <- x*y
测试源.Rmd
Can I run another script from Rmd
========================================================
Testing if I can run "test of source to rmd.R"
```{r first part}
require(knitr)
read_chunk("test of source to rmd.R")
a <- z-1000
a
```
The above worked only if I replaced "read_chunk" with "source". I
can use the vectors outside of the code chunk as in inline usage.
So here I will tell you that the first number is `r a[1]`. The most
interesting thing is that I cannot see the variables in RStudio
workspace but it must be there somewhere.
【问题讨论】: