首页 > 解决方案 > 使用库 rtf 将 R 表达式插入单词

问题描述

我想知道它是否可能将 R 表达式或 R 对象插入到一个单词中:

例子:

  data(mtcars)

    (table=head(mtcars,20))
    addParagraph(doc, "\n\n Table cars \n")
    addTable(doc, cbind(rownames(table), table))
    nrow(mtcars)

    In this table we can see that data contain nrow(mtcars) rows

但用我的话来说会显示:

    "In this table we can see that data contain 32 rows"

在此先感谢 R

标签: rinsertrtf

解决方案


最后我可以在一个词中插入一个对象。使用 rtf 和胶水包:

library(rtf)
library(glue)

data(mtcars)
total=nrow(mtcars)
addText(todo, glue("In this table we can see that data contain {nrow(mtcars)} rows"))

我的话显示:

"In this table we can see that data contain 32 rows"

推荐阅读