我在 Mac OS 中编写了一个 bash 脚本,它获取我的 .rnw 文件,编织它,然后制作一个 .pdf。为了编织我的文件,我正在使用命令
Rscript -e "library(knitr); knit('file.rnw', encoding='utf8')"
一切正常。但是,我不想在最终文档中使用## 字符。我使用 R 提示符测试了以下命令
library(knitr)
opts_chunk$set(comment=NA)
knit('file.rnw', encoding='utf8')
他们给我的正是我想要的:R 命令输出中没有注释的文档。但是如果我尝试运行
Rscript -e "library(knitr); opts_chunk$set(comment=NA); knit('livro.rnw', encoding='utf8')"
我明白了
Error: could not find function "opts_chunk"
Execution halted
作为结果。我究竟做错了什么?我如何使用命令行在 knitr 中请求我的 block 的选项?
最佳答案
我不确定易辉说“把答案移到这里”是什么意思,但这里是易辉批准的 Duncan Murdoch 的 R-help 答案:
That looks like a bash problem: it appears to be replacing $set with a blank string. Use appropriate quoting or escaping to tell it not to do that. (I think using single quotes around the command will work; you'll need double quotes within it.)
并且一辉补充道:
Yes I believe that was the problem. Same question asked here: https://github.com/yihui/knitr/issues/162#issuecomment-9017997
关于r - 当我将 knitr 和 Rscript 与 opts_chunk 一起使用时执行停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15640353/