Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

R语音能否和LaTeX或者markdown结合生成带参数的文本?

R语言和LaTeX、markdown结合为我们编写、生成报告提供了极大的便利,可是在日常使用中,R语言和排版语言两者的结合还是比较僵化,代码都是分开放、分开生成到输出才拼接到一起

有没有一种方法,能让R语言的运行结果插入文字段落中的特定位置?
eg:R语言运行后参数结果为a=14,那么文本段落中可以复用这个参数a,
就像Excel中的引用单元格
或者Python的 '运行结果为%s' % a

希望大神不吝分享探讨~


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Rmarkdown:

文本(smaller是数据集diamonds的子集):

We have data about `r nrow(diamonds)` diamonds.
Only `r nrow(diamonds) - row(smaller)` are larger than 2.5 carats.
The distribution of the remainder is shown below:

显示效果:

We have data about 53940 diamonds.
Only 126 are larger than 2.5 carats.
The distribution of the remainder is shown below:

——来自《R for Data Science》

再加一个简单的例子:

## test

```{r}
nsp <- length(unique(iris$Species))
```
number of species is `r nsp`

输出html显示出来是number of species is 3


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...