使用R包RefManageR调整文本引文

时间:2018-02-08 18:05:13

标签: r regex r-markdown bibtex citations

我正在尝试使用RRefManageR来管理参考书目,如下所示。

library(RefManageR)
file.name <- system.file("Bib", "RJC.bib", package="RefManageR")
bib <- ReadBib(file.name)

BibOptions(check.entries = FALSE, bib.style = "authoryear", max.names = 1,
           style = "citation", bibpunct = c("(",")","(",")",";",","))

Cite(bib, c("jennings2013bayesian", "ritchie2012novel"))
[1] "(Jennings, et al., 2013; Ritchie, et al., 2012)"

如何调整引文中的标点符号以获得以下所需引用(之前没有逗号)?

[1] "(Jennings et al., 2013; Ritchie et al., 2012)"

bibpunct参数似乎没有可用的选项。

1 个答案:

答案 0 :(得分:1)

您可以使用这样的简单正则表达式:

, (?=et al\.)
# match a comma, only when it is followed by et al.

然后需要用一个空格替换,请参阅a demo on regex101.com

<小时/> 在R

ref <- c("(Jennings, et al., 2013; Ritchie, et al., 2012)")
(ref <- gsub(", (?=et al\\.)", " ", ref, perl=TRUE))

<小时/> 这产生了

[1] "(Jennings et al., 2013; Ritchie et al., 2012)"