首页 > 解决方案 > 如何使用 rmarkdown 将带有句子的小标题转换为 Microsoft Word 中的项目符号

问题描述

我有一个 excel 文件,其中有一列包含我正在读入 R 作为 tibble 的评论。然后我想使用 rmarkdown 将每个评论编织成一个项目符号点(或只是一个新的句子)。下面的代码复制了一个小样本来复制我所拥有的 -

library(tidyverse)
comments <- 
  c("I haven't experienced a proactive approach to our work but rather reacting and responding to community needs",
    "The board does not have regular exposure to many staff")

comments <- comments %>% as_tibble()

这是我在编织单词时想要实现的目标 -

在此处输入图像描述

我尝试使用以下代码 -

for(row in comments){
   cat("\n", row, "\n")
}

但是,它不会添加间距,只会像单个段落一样打印 tibble 的所有行。任何帮助都感激不尽。

标签: rr-markdownstringr

解决方案


您需要使用-或指定列表结构*。两者都应该工作。请记住results='asis'块选项。例子

```{r, results='asis'}
for(row in comments){
  cat(paste0("* ", row, "\n"))
}
```

甚至更简单(但可能是作弊,因为它一次只允许一列)

```{r, results='asis'}
cat(paste0("- ",comments[[1]], "\n"))
```

推荐阅读