8

如何使用带有 knitr 的内联表达式包含变量。

例如,这按预期工作:

A random number from the normal distribution `r rnorm(1)`.

但是如果你想打印一个预定义的字符串/数字:

```{r}
company <- "ABC Co"
```

Some text about `r company`

编织后不打印任何内容。有什么东西需要包起来吗


根据请求更新会话信息:

R version 3.0.0 (2013-04-03)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8    LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] slidify_0.3.3 knitr_1.2    

loaded via a namespace (and not attached):
[1] digest_0.6.3   evaluate_0.4.3 formatR_0.7    markdown_0.5.4 stringr_0.6.2  tools_3.0.0    whisker_0.1   
[8] yaml_2.1.7   
4

1 回答 1

8

包装变量I()使其按预期工作。

```{r}
company <- "ABC Co"
```

Some text about `r I(company)`

虽然 .Rmd 没有明确说明,但在此处记录:http: //yihui.name/knitr/demo/output/

于 2013-04-16T19:12:21.497 回答