Managing References in R Markdown and Rnoweb

2019-11-15 • One minute to read

When writing my dissertation I found it difficult to dynamically manage references to R packages that I had used along the way. For the main document refernces I use Zotero which makes managing these trivial, but for packages, it wasn’t quite a simple.


To prevent loading in all R packages required for each script I created for my dissertation, I decided to create a central script containing them all, along with functions I had created. Within this central script, using the R package pacman I was able to install and load packages as required with one command;

pkgs <- c(
pacman::p_load(pkgs, character.only = T)

Given the object pkgs now provides a list of all packages used in the analysis, this can be used to extract all the required references. In the main document:

write.bib(pkgs, "rbib.bib")
  paste0(pkgs, collapse = ",", sep = ""), "}"

The output of this code is a .bib file containing all references to packages loaded, and in order to add each package to the bibliography without directing citing, the chunk adds the LaTex command \nocite{} containing all packges.


University of Liverpool R Markdown Templates

Scripting in Bash to Export pdfs to a Kindle