当使用rmarkdown时,通常情况下是要以编程方式生成文本片段,尤其是要列出正在使用的项目。例如;

The species of iris examined were `r cat(as.character(unique(iris$Species)), sep = ", ")`.

哪个会产生



为了正确阅读它应该是



有没有简单的方法可以做到这一点?

最佳答案

这是pander软件包中的有用工具之一。

pander::p



例子:

devtools::install_github('Rapporter/pander')
## also available on cran:
# install.packages('pander')

library(pander)

p(levels(iris$Species), wrap = '')
# "setosa, versicolor and virginica"

p(levels(iris$Species), wrap = '', copula = ', and ')
# "setosa, versicolor, and virginica"

关于string - 在R中以 "V, W, X, Y, and Z"样式输出列表的简单方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24581223/

10-12 15:36