I am trying to manage a bibliography using the R
package RefManageR
as follows.
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)"
How to adjust the punctuation within the citation so as to get the following desired citation (without comma before et al)?
[1] "(Jennings et al., 2013; Ritchie et al., 2012)"
There seems to be no option available with the bibpunct
argument.
You could use a simple regular expression like this:
, (?=et al\.)
# match a comma, only when it is followed by et al.
This needs to be replaced by a single space then, see 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)"