Welcome to my Open Notebook

This is an Open Notebook with Selected Content - Delayed. All content is licenced with CC-BY. Find out more Here.

ONS-SCD.png

Sanitize mendeley references in r markdown reporting

A key challenge for Reproducible Research Reports in Rmarkdown remains adequate scholarly citation management; the machinery of scholarly citations and references.

The knitcitations R package does a great job of working with bibtex bibliography files, however the bibtex manager that I use is Mendeley and it has implemented some rules on the way it handles special characters that forces the bibtex references into a state with some ‘escaped’ elements that breaks their presentation via knitcitations.

This is a post from my open notebook that shows the workaround I am using for sanitizing the Mendeley escaped underscores in URLS.

Here is an example:

There is considerable public health impact from the effects on mental of drought (Sarathi Biswas 2012). It is proposed that the best method to disentangle the multifactorial nature of this causal mechanism is the ‘five-capitals’ framework, indeed this method may even enable understanding the human carrying capacity of ecosystems (McMichael & Butler 2002).

McMichael, A.J. & Butler, C.D. (2002). Global health trends: Evidence for and against sustainable progress. International Union for the Scientific Study of Population Committee on Emerging Health Threats. http://www.demogr.mpg.de/papers/workshops/020619{\_}paper25.pdf [21 Sep. 2003]

Sarathi Biswas, P. (2012). Alcohol, drought lead to farmer’s suicide. Daily News and Analysis. http://www.dnaindia.com/pune/report{\_}alcohol-drought-lead-to-farmers-suicide{\_}1688976 [17 May 2012]

See those pesky curly braces { and } around the underscores?

The fix

The fix I am using is to sanitize each record where this is an issue as I build my document, so the mendeley version stays as-is, while the R version has been sanitized by removing the escape characters.

# read mendeley bibtex file
bib <- read.bibtex("~/references/library.bib")
# ad hoc fix
for(bibkey in c("SarathiBiswas2012", "Mcmichael2002a")){
  bib[ [ bibkey ] ]$url <- gsub("\\{\\\\_\\}","_", bib[ [ bibkey ] ]$url)
}

This is the result:

McMichael, A.J. & Butler, C.D. (2002). Global health trends: Evidence for and against sustainable progress. International Union for the Scientific Study of Population Committee on Emerging Health Threats. http://www.demogr.mpg.de/papers/workshops/020619_paper25.pdf [21 Sep. 2003]

Sarathi Biswas, P. (2012). Alcohol, drought lead to farmer’s suicide. Daily News and Analysis. http://www.dnaindia.com/pune/report_alcohol-drought-lead-to-farmers-suicide_1688976 [17 May 2012]

Posted in  disentangle Reproducible Research Reports


blog comments powered by Disqus