无法更改Rmd文档中的参数 [英] Can't change params in Rmd documents
问题描述
如此站点所述,可以在Rmarkdown的YAML标头中定义参数文件和在那里指定的默认值可以用rmarkdown::render("foo.Rmd", params = list(param1 = "bar")
覆盖.但是,当我尝试此操作时,出现以下错误:
As explained on this site it is possible to define parameters in the YAML header of a Rmarkdown file and the default values specified there can be overwritten with rmarkdown::render("foo.Rmd", params = list(param1 = "bar")
. However when I try this I get the following error:
参数对象已经存在于编织环境中,因此不能被渲染参数覆盖
这是最小的可复制Rmd文档.假设文件名为test.Rmd
.
Here is a minimal reproducible Rmd document. Let's say the file name is test.Rmd
.
---
title: "Test"
output: pdf_document
params:
name: Andreas
---
Hello, my name is `r params$name`.
当我现在尝试rmarkdown::render("test.Rmd", params = list(name = "Jordan")
时,它会因上述错误而停止.
When I now try rmarkdown::render("test.Rmd", params = list(name = "Jordan")
it stops with the error written above.
这是我的sessionInfo()
:
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin14.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)
locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.11 rmarkdown_0.7.3
loaded via a namespace (and not attached):
[1] Rcpp_0.12.0 XML_3.98-1.3 digest_0.6.8 MASS_7.3-40 grid_3.2.1
[6] plyr_1.8.3 gtable_0.1.2 magrittr_1.5 scales_0.2.5 ggplot2_1.0.1
[11] stringi_0.5-5 reshape2_1.4.1 jwiDlst_0.1.1 proto_0.3-10 tools_3.2.1
[16] stringr_1.0.0 munsell_0.4.2 yaml_2.1.13 parallel_3.2.1 colorspace_1.2-6
[21] htmltools_0.2.6
感谢您的帮助!
推荐答案
错误消息表明您在当前工作空间中已经有一个名为params
的对象,应在调用ls()
仔细检查当前环境中的对象.
The error message indicates you have already got an object named params
in your current workspace, and you should remove it (rm(params)
) before calling rmarkdown::render()
. Use ls()
to double check the objects in the current environment.
这篇关于无法更改Rmd文档中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!