继续question ...如果我想输出单独的R代码文件,我不知道在哪里设置knitr选项。以下内容未在我的工作目录中提供预期的附加.R文件。
---
output: ioslides_presentation
---
```{r setup, include=FALSE}
library("knitr"); purl("myfile.rmd")
#library("knitr"); knit("test_tangle.Rmd", tangle = TRUE)
#opts_knit$set(tangle=TRUE)
```
## Slide with Plot
```{r, echo=TRUE}
plot(cars)
```
但错误信息......
Quitting from lines 6-7 (myfile.rmd)
Error in readLines(if (is.character(input2)) { :
cannot open the connection
Calls: <Anonymous> ... withVisible -> eval -> eval -> purl -> knit -> readLines
Execution halted
答案 0 :(得分:1)
我建议你改用hook_purl
功能。函数purl()
(或等效地,knit(tangle = TRUE)
)在某些情况下可能无法工作,并且钩子函数hook_purl()
更可靠。有关详细信息,请参阅?hook_purl
。
---
output: ioslides_presentation
---
```{r setup, include=FALSE}
library("knitr")
knit_hooks$set(purl = hook_purl)
```
## Slide with Plot
```{r, echo=TRUE}
plot(cars)
```
然后在编织文档时,将自动生成R脚本。