[英]Using knitr to create HTML slides and separate R code file
Following on from this question ... I am not sure where to set knitr option if I want to output a separate file of R code. 接下来是这个问题 ……如果我想输出一个单独的R代码文件,我不确定在哪里设置knitr选项。 The following does not provide the expected additional .R files in my working directory.
以下内容在我的工作目录中未提供预期的其他.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)
```
but an error message... 但是错误消息...
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
I recommend you to use the hook_purl
function instead. 我建议您改用
hook_purl
函数。 The function purl()
(or equivalently, knit(tangle = TRUE)
) may fail to work in certain cases, and the hook function hook_purl()
is more reliable. 函数
purl()
(或等效地, knit(tangle = TRUE)
)在某些情况下可能无法工作,并且钩子函数hook_purl()
更可靠。 See ?hook_purl
for more information. 有关更多信息,请参见
?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)
```
Then as you knit the document, the R script will be automatically generated. 然后,当您编织文档时,将自动生成R脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.