r - 当我将 knitr 和 Rscript 与 opts_chunk 一起使用时执行停止

标签 r bash knitr rscript

我在 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/

相关文章:

r - 如何解决 R Markdown (Knit) "'closure' is not subsettable"?

R fread data.table 速度不一致

r - 从 data.frame 中提取行

xml_grep 获取节中的相关信息

Linux 符号链接(symbolic link)目录中的所有文件都添加了 '*'

r - 为什么 knitr 代码块中的 $PATH 与终端中的 $PATH 不同?

r - 在 Rcpp 中构建 3D 数组

r - .wav 文件长度/持续时间,无需读取文件

string - Bash:用空字符串替换子字符串

r - 使用 condformat 和 Knir 在 pdf 上创建表格?