Nick logo Credibly Curious

Nick Tierney's (mostly) rstats blog

2021-03-19

How to Cite R Packages Like R Markdown

Nicholas Tierney

Categories: rstats rmarkdown citation bibtex Tags: rstats bibtex citation rmarkdown

5 minute read

A friend recently asked me how to cite the R package, “rmarkdown” in their work. Here is how to do just that!

You can get the information straight from R, like so:

citation("rmarkdown")
#> 
#> To cite the 'rmarkdown' package in publications, please use:
#> 
#>   JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi
#>   and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and
#>   Winston Chang and Richard Iannone (2021). rmarkdown: Dynamic
#>   Documents for R. R package version 2.7. URL
#>   https://rmarkdown.rstudio.com.
#> 
#>   Yihui Xie and J.J. Allaire and Garrett Grolemund (2018). R Markdown:
#>   The Definitive Guide. Chapman and Hall/CRC. ISBN 9781138359338. URL
#>   https://bookdown.org/yihui/rmarkdown.
#> 
#>   Yihui Xie and Christophe Dervieux and Emily Riederer (2020). R
#>   Markdown Cookbook. Chapman and Hall/CRC. ISBN 9780367563837. URL
#>   https://bookdown.org/yihui/rmarkdown-cookbook.
#> 
#> To see these entries in BibTeX format, use 'print(<citation>,
#> bibtex=TRUE)', 'toBibtex(.)', or set
#> 'options(citation.bibtex.max=999)'.

This provides you with the citation as you might have in the final body of text.

And if you use BibTex to manage your citations you can do the following (as it hints to in the previous output):

print(citation("rmarkdown"), bibtex = TRUE)
#> 
#> To cite the 'rmarkdown' package in publications, please use:
#> 
#>   JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi
#>   and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and
#>   Winston Chang and Richard Iannone (2021). rmarkdown: Dynamic
#>   Documents for R. R package version 2.7. URL
#>   https://rmarkdown.rstudio.com.
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Manual{,
#>     title = {rmarkdown: Dynamic Documents for R},
#>     author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang and Richard Iannone},
#>     year = {2021},
#>     note = {R package version 2.7},
#>     url = {https://github.com/rstudio/rmarkdown},
#>   }
#> 
#>   Yihui Xie and J.J. Allaire and Garrett Grolemund (2018). R Markdown:
#>   The Definitive Guide. Chapman and Hall/CRC. ISBN 9781138359338. URL
#>   https://bookdown.org/yihui/rmarkdown.
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Book{,
#>     title = {R Markdown: The Definitive Guide},
#>     author = {Yihui Xie and J.J. Allaire and Garrett Grolemund},
#>     publisher = {Chapman and Hall/CRC},
#>     address = {Boca Raton, Florida},
#>     year = {2018},
#>     note = {ISBN 9781138359338},
#>     url = {https://bookdown.org/yihui/rmarkdown},
#>   }
#> 
#>   Yihui Xie and Christophe Dervieux and Emily Riederer (2020). R
#>   Markdown Cookbook. Chapman and Hall/CRC. ISBN 9780367563837. URL
#>   https://bookdown.org/yihui/rmarkdown-cookbook.
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Book{,
#>     title = {R Markdown Cookbook},
#>     author = {Yihui Xie and Christophe Dervieux and Emily Riederer},
#>     publisher = {Chapman and Hall/CRC},
#>     address = {Boca Raton, Florida},
#>     year = {2020},
#>     note = {ISBN 9780367563837},
#>     url = {https://bookdown.org/yihui/rmarkdown-cookbook},
#>   }

And then you can copy and paste this into your .bibtex file.

How to customise your own citations

You can create your own custom way to cite your R package by adding a CITATION file in your inst directory like so. Which reminds me, I’ve got to do this for my R package, naniar…

Post script: A thought/issue on automating clipboards.

I normally use the clipr package by Matthew Lincoln to save R output to the clipboard, but in this case it didn’t quite work, as this, returned:

library(clipr)
write_clip(citation("rmarkdown"))
Warning message:
In flat_str(content, breaks) : Coercing content to character

And then this as the output:

list(title = "rmarkdown: Dynamic Documents for R", author = list(list(given = "JJ", family = "Allaire", role = NULL, email = NULL, comment = NULL), list(given = "Yihui", family = "Xie", role = NULL, email = NULL, comment = NULL), list(given = "Jonathan", family = "McPherson", role = NULL, email = NULL, comment = NULL), list(given = "Javier", family = "Luraschi", role = NULL, email = NULL, comment = NULL), list(given = "Kevin", family = "Ushey", role = NULL, email = NULL, comment = NULL), list(given = "Aron", 
    family = "Atkins", role = NULL, email = NULL, comment = NULL), list(given = "Hadley", family = "Wickham", role = NULL, email = NULL, comment = NULL), list(given = "Joe", family = "Cheng", role = NULL, email = NULL, comment = NULL), list(given = "Winston", family = "Chang", role = NULL, email = NULL, comment = NULL), list(given = "Richard", family = "Iannone", role = NULL, email = NULL, comment = NULL)), year = "2021", note = "R package version 2.7", url = "https://github.com/rstudio/rmarkdown")
list(title = "R Markdown: The Definitive Guide", author = list(list(given = "Yihui", family = "Xie", role = NULL, email = NULL, comment = NULL), list(given = "J.J.", family = "Allaire", role = NULL, email = NULL, comment = NULL), list(given = "Garrett", family = "Grolemund", role = NULL, email = NULL, comment = NULL)), publisher = "Chapman and Hall/CRC", address = "Boca Raton, Florida", year = "2018", note = "ISBN 9781138359338", url = "https://bookdown.org/yihui/rmarkdown")
list(title = "R Markdown Cookbook", author = list(list(given = "Yihui", family = "Xie", role = NULL, email = NULL, comment = NULL), list(given = "Christophe", family = "Dervieux", role = NULL, email = NULL, comment = NULL), list(given = "Emily", family = "Riederer", role = NULL, email = NULL, comment = NULL)), publisher = "Chapman and Hall/CRC", address = "Boca Raton, Florida", year = "2020", note = "ISBN 9780367563837", url = "https://bookdown.org/yihui/rmarkdown-cookbook")

I’m not sure how to get around this, but I’m probably missing something obvious, if there are any suggestions, I’m all ears!