首页 > 解决方案 > Pandoc 的 Markdown 中列表的文本格式

问题描述

为了创建项目符号列表格式,我在 sampleList 元素中添加了星号和新的换行符:


sampleList <- list(1, 2, 3)

# Create bulleted list
createPoints = function(list) {
  # Pre-allocate list
  setList <- vector(mode = "list", length = length(list))

  # Add elements to each line
  for (i in seq_along(list)) {
    line = sprintf("* %s  \n", list[[i]])
    setList[[i]] <- line
  }
  
  return(setList)
}

finalList = createPoints(sampleList)

输出:

[[1]]
[1] "* 1  \n"

[[2]]
[1] "* 2  \n"

[[3]]
[1] "* 3  \n"

如何打印项目符号子列表中的各个元素?

这不起作用:

我的输出带有额外的逗号,子列表没有项目符号:

我希望它看起来像这样:

标签: rfor-loopr-markdownpandocword

解决方案


取消列出您的finalList对象并将所有元素折叠在一起以避免逗号

sampleList <- list(1, 2, 3)

# Create bulleted list
createPoints = function(list) {
  # Pre-allocate list
  setList <- vector(mode = "list", length = length(list))

  # Add elements to each line
  for (i in seq_along(list)) {
    line = sprintf("* %s  \n", list[[i]])
    setList[[i]] <- line
  }
  
  return(setList)
}

finalList = unlist(createPoints(sampleList))

r paste(finalList, collapse = " ")


推荐阅读