有没有办法使用 R 的方式从 R Markdown 文件列表中生成 yaml 标题标题列表?假设你有两个文件
A.Rmd
---
title: Titel of first file
---
B.Rmd
---
title: Titel of second file
---
那么列表应该如下所示
File |Title
-----|--------------------
A.Rmd|Titel of first file
B.Rmd|Titel of second file
这个列表也可以生成为 R Markdown 文件吗 - 最好带有原始文件的链接?
最佳答案
这是一个小而方便的函数,它为您提供标题和文件名:
read_RMD_titles <- function(files){
names_list <- lapply(1:length(files), function(x){
title <- readLines(files[x])[2]
return(c(files[x], title))
})
return(unlist(names_list))
}
read_RMD_titles(files = c("A.Rmd", "B.Rmd"))
# [1] "A.Rmd" "title: \"Untitled\""
# [3] "B.Rmd" "title: \"Untitled\""
您现在可以根据自己的需要修改此方法。这应该是一个起点。
关于r - 从 R Markdown 文件列表的 yaml 标题标题生成目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39703811/