[英]R Markdown Parameters - can I combine vectors to use as parameters?
If you type summary(c(mtcars, cars))
into your console you will receive output. 如果在控制台中键入
summary(c(mtcars, cars))
您将收到输出。 But the following R Markdown (shown below) throws the error, " object 'test' not found ". 但是随后的R Markdown(如下所示)将引发错误,“ 未找到对象'test' ”。
How do I combine vectors to use as parameters in R Markdown? 如何在R Markdown中组合向量以用作参数? Maybe this is not allowed and parameters must be either single numbers, or character strings??
也许这是不允许的,并且参数必须是单个数字或字符串? I want the
test
parameter to be c(mtcars, cars)
. 我希望
test
参数为c(mtcars, cars)
。 Or perhaps in the future I'll have a parameter VariableX
that I'd want to be c("apple", "pear", "orange")
. 或者,也许将来我会有一个想要成为
c("apple", "pear", "orange")
的参数VariableX
。
---
title: "Untitled"
output: html_document
params:
n: 100
test: c(mtcars, cars)
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r test}
summary(test)
```
As explained in the R Markdown book : 如R Markdown书中所述 :
We can also use R objects by including !r before R expressions
我们还可以通过在R表达式之前包含!r来使用R对象
To access the parameter within the report using params$test
. 使用
params$test
访问报表中的params$test
。 Putting this together: 放在一起:
---
title: "Untitled"
output: html_document
params:
n: 100
test: !r c(mtcars, cars)
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r test}
summary(params$test)
```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.