r - 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"
如何打印项目符号子列表中的各个元素?
这不起作用:
- 子弹 1
r finalList
我的输出带有额外的逗号,子列表没有项目符号:
子弹 1
- 1
, * 2
, * 3
我希望它看起来像这样:
- 子弹 1
- 1
- 2
- 3
解决方案
取消列出您的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 = " ")
推荐阅读
- java - 我在华为 AppGallery 上发布我的应用后,Admob 广告没有显示
- javascript - 如何从返回语句中检索谷歌驱动文件的绝对链接?
- c++ - 在 C++ 中使用 {} 声明变量时出错
- javascript - 如何在 POST 请求后正确呈现新元素?
- rust - 使用 rust 从网站上抓取由混淆的 JS 代码生成的数据
- java - 为什么 ResponseBody 和 Jackson ObjectMapper 不返回相同的输出?
- c# - 使用 C# 更新 SQL 表
- kernel - 内核是否跟踪进程在内存中的启动位置或 CPU?
- amazon-web-services - 非法指令(核心转储)docker、red hat 7.7、aws ec2
- html - Flexbox 不工作 - 它似乎只适用于某些子元素?