Skip to content

Instantly share code, notes, and snippets.

@briandk
Created April 9, 2017 18:21
Show Gist options
  • Save briandk/3dbfcdaea2b2d0dea699a9febd830627 to your computer and use it in GitHub Desktop.
Save briandk/3dbfcdaea2b2d0dea699a9febd830627 to your computer and use it in GitHub Desktop.
Wil Doane's system for automatically generating bibliography entries for the R packages you're using
# Early in the script
pkgs_pre_script <- try(devtools::loaded_packages(), silent = TRUE)
# Late in the script
pkgs_used_during_script <- try(devtools::loaded_packages(), silent = TRUE)
cat("* ")
print(citation(), style="text") # or Bibtex or LaTeX
if ((class(pkgs_pre_script) != "try-error") &
(class(pkgs_used_during_script) != "try-error")) {
for (pkg in dplyr::anti_join(pkgs_used_during_script,
pkgs_pre_script,
by = "package")$package) {
cat("* ")
print(citation(pkg), style="text")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment