简体   繁体   English

如何从字符串列表(引用键)中获取单个字符串(pandoc引用)

[英]How to get a single string (a pandoc citation) from list of strings (citation keys)

I'm working with a list object consisting of a variable number of citation keys. 我正在使用由可变数量的引证键组成的列表对象。

mylist <- structure(list(steele1998pulsus = "steele1998pulsus", wright1997evaluation = "wright1997evaluation", wright1996continuous = "wright1996continuous"), .Names = c("steele1998pulsus", "wright1997evaluation", "wright1996continuous")) 

paste0("@", unlist(mylist)) 

generates: 产生:

[1] "@steele1998pulsus"     "@wright1997evaluation" "@wright1996continuous"

I've tried various combinations of cat() and paste() without success - my goal is a text string formatted as below (a pandoc citation of multiple keys). 我尝试了cat()和paste()的各种组合,但均未成功-我的目标是将文本字符串设置为如下格式(多个键的pandoc引用)。

[@steele1998pulsus; @wright1997evaluation; @wright1996continuous]

I'm not great with R's string-processing commands (I find it very hard to remember the difference between collapse and sep ) but I can do it like this: 我对R的字符串处理命令不是很满意(我很难记住collapsesep之间的区别),但是我可以这样做:

paste("[", paste(paste0("@", mylist), collapse="; "), "]", sep="")

Producing the desired output: 产生所需的输出:

> paste("[", paste(paste0("@", mylist), collapse="; "), "]", sep="")
[1] "[@steele1998pulsus; @wright1997evaluation; @wright1996continuous]"

Also, because we don't need the sep argument for any of the steps we can just use paste0 for all of them: 另外,由于我们不需要任何步骤的sep参数,因此可以对所有步骤都使用paste0

paste0("[", paste0(paste0("@", mylist), collapse="; "), "]")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM