Citing R packages

I am having trouble citing R packages in the Nature formatting style. Whatever item type I use (I've tried Computer Program, Journal Article, Report, Book), they are not displayed as suggested in R. The URL and the version number are missing.

Which item type do you suggest, so that both URL and version number are cited?

According to R, the output should be like this: (I assume this is APA style)
Wickham, H. and Henry, L. (2018). tidyr: Easily Tidy Data with 'spread()' and 'gather()' Functions. R package version 0.8.1. https://CRAN.R-project.org/package=tidyr

So adapted for Nature, it should be:
Wickham, H. and Henry, L. tidyr: Easily Tidy Data with 'spread()' and 'gather()' Functions. R package version 0.8.1. https://CRAN.R-project.org/package=tidyr (2018)
  • citation("tidyr") should give you a bibtex format, no?
  • We simply don't account for computer Programs in Nature style currently. Could probably be added
  • Yes, citation ("tidyr") gives me the bibtex format, that's how I created the above citation examples. I'll simply have to add it manually to the reference section for now. Adding it would be great!
  • But it's just a suggestion provided by R, not an obligation.
  • Alright, thank you! I like giving the authors credits for their packages, that's all. :)
  • Citing is mandatory, the format is only suggested
  • Ok, thank you for specifying. You're right, the format is not obligatory, but version number and URL are essential, and not currently included in the Nature style. Adding the references manually is a solution for now.

    Thanks for your quick answers!
  • right, but the version number would certainly be part of a citation for software in any style.
  • Hi, I am looking for the same thing, a possibility to add R-package references directly via Zotero.

    I checked another post from 2013 looking for a way to do this.

    Before I stardted using Zotero, I wrote references manually and now that I do use it, I'm affraid of messing things up if I do that.

    My idea right now is to split my Bibliography between R packages and scientific articles.

    Would you advise I wait until the very end and unlink citations before mixing R packages with scientifc articles and having references strictly follow journal guidelines ?

    I might need to move things again even if I think adding R package references will be the last thing I do, so I am reluctant to think about that option.
  • You can add R packages to Zotero directly from CRAN. Some citation styles cite them properly. If you are using one that doesn't, let is know which and provide a sample citation from the guidelines or a recent paper

  • Thank you very much. I am currently using the Springer - Basic (author-date, no "et al.") style since I noticed that the current version I have of Wiley's "Plant pathology" style does not include "usual articles" DOIs (for me at least), and someone pointed out to me in another discussion I had mixed up the two. I just checked and it seems that Springer - Basic (author-date, no "et al.") does not yet (once again for me at least) include DOIs for links I get from CRAN.
  • Could you given an example -- most R packages don't have DOIs unless there's a companion publication in JOSS or the like.

  • Yes, here is what I have recieved from using "citation("lme4")" in R:

    Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1-48. doi:10.18637/jss.v067.i01.

    And here is what the Springer - Basic (author-date, no "et al.") style gives me after i click the "save to zotero" button from CRAN for lme4:

    Bates D, Maechler M, Bolker [aut B, cre, Walker S, Christensen RHB, Singmann H, Dai B, Scheipl F, Grothendieck G, Green P, Fox J, Bauer A, simulate.formula) PNK (shared copyright on (2021) lme4: Linear Mixed-Effects Models using “Eigen” and S4.

  • The issue is that the citation() function asks you to cite the journal article published in JSS, not the R package directly from CRAN. You should add the JSS article citation by DOI and cite that.
  • edited July 1, 2021
    We aren't currently trying to get the citation info from CRAN for packages with associated publication, just parsing the metadata. If you want to cite the JSS article, just import the item via DOI in the add by identifier field.
  • @adamsmith Yeah, the CITATION information in packages is honestly very inconsistent. It usually takes a fair amount of human judgment to decide what to do with it. The BibTeX especially isn’t really reliably formatted since it’s human-constructed typically. I think the basic strategy currently used it correct—I’ve been taking some notes on places where the metadata parsing could be improved that I’ll open an issue for.
  • I don't know if this will be useful for you in 2021 but you can simple create a .bib file of all packages loaded using " knitr::write_bib(c(.packages(), "bookdown"), "packages.bib") ". Then skim through to validate/update the entries before importing to Zotero ( by double clicking on the .bib you just created)

    The first argument should be a character vector of package names, and the second argument is the path to the .bib file. In the above example, .packages() returns the names of all packages loaded in the current R session. This makes sure all packages being used will have their citation entries written to the .bib file. When any of these packages are updated (e.g., the author, title, year, or version of a package is changed), write_bib() can automatically update the .bib file.


    See https://bookdown.org/yihui/rmarkdown-cookbook/write-bib.html for more information
  • Note that often those bib files will produce incorrect citations, especially for APA style. So always double check how the data imports into Zotero and clean as necessary.
  • I also created a .bib file with the R package citations that I needed and imported them to Zotero.
    Most packages I want to cite are referenced as type "Manual," but that's not one of Zotero's item type options.

    Zotero imported them as type "book," and the package version is imported in a nested note. That note won't be displayed in any formatting style.

    So I tried by changing the type to "Software" and the "note" tag for a "version" tag in the .bib file, but that still doesn't provide the recommended citation.

    Any other ideas on how to change the bib file to get the citation they recommend?

    Maybe Zotero devs can create a "Manual" item type that supports note tags and show them in most citation styles?

  • I don't quite understand what you are trying to do, but generally speaking, there's no reason to try to recreate "recommended citations": correct software citations differ by citation style, just like correct citations for journal articles do.

    Also, while .bib is widely used, it's at the same time quite limited and poorly standardized, so if at all possible I'd avoid taking a .bib file as a starting point. Why not start in Zotero?
  • Thanks for the answer.
    I'm trying to add R package citations to Zotero in tandem (instead of one by one).
    Every R package provides the information needed to be cited (in the DESCRIPTION file), and some R functions compile that information and create a .bib file.

    That's why a .bib file is my starting point. Unfortunately, .bib is indeed very limited and poorly standardized, especially when created from the R packages description file.

    I'm aware that correct citation depends on citation style and that I don't need to recreate the recommended citation. However, I agree with Hannah that URL and version are essential and should be reported in most citation styles.

    So, my question is simply what the best item type for an R package citation would be to show both URL and version most of the time?
  • Folks, to be clear, you should enter R packages in Zotero as “Software”. Generally, the best place to start with importing them to Zotero is the CRAN package page with the Zotero connector button in your browser toolbar, which will include version and URL. From there, you can make minor tweaks to the data (eg, to add “R package” to the Programming Language field so that is labeled in APA style).

    You can check the CITATION information in the package to see if the author would prefer a journal article be cited (in that case, I strongly suggest citing _both_ the package itself and the article), but I would rely on the metadata from CRAN for the package, as this will be more up to date and accurate
  • Thanks bwiernik! That’s very clear.
Sign In or Register to comment.