如何将数据框中的文本包含为标题或段落?

How to include text from a dataframe as heading or paragraph?

我正在使用 knitr 制作动态 HTML 网站。我想将数据框中的文本作为普通文本包含在内。

#my dataframe
text 
my first paragraph
my second paragraph

在 knitr 中,我可以使用 cat()print(),但它们会以 R 输出样式生成丑陋的块。

{r 
   cat(text)
   print(text)
}

能不能像写markdown一样输出text/strings的"normal paragraph"样式?

还是创建新主题更快或更容易?

更新:我正在遍历数据帧 df

variable1, variable2, text
2, 10, hello
5, 11, hi

for (i in unique(df$text) {
    p <- ggplot(df, aes(variable1, variable2)) + geom_point()

   cat(df$text)
   print(p)


}

您可以使用以下块:

```{r, results='asis', echo=FALSE}
cat(paste("<p>", df$text, "</p>"), sep = "\n")
```

此处,df$text 中的所有字符串都包含在一个 p 标记中(HTML 段落)。参数 results='asis' 允许将结果解释为 HTML(不是 R 输出块)。

因此 df$text 中的所有字符串将显示为单独的段落。