Add citations to R and R packages in an R Markdown report.
Usage
cite_r(pkgs = c("tidyverse", "gtsummary"), add_citations = TRUE)
Arguments
- pkgs
character vector of package names to cite. Default is
c("tidyverse", "gtsummary")
.NULL
is acceptable.- add_citations
logical indicating whether to include the bibtex citations of R and the packages. Default is
TRUE
. When TRUE, we expect the R markdown file to reference a bib file including the references for each package listed in thepkgs=
argument. The cite key for each of these entries must match the package name. Also, the file must include an entry for R with cite key 'r'.
R Markdown
Below is an example how the cite_r()
function would be used in an R
Markdown report.
---
: html_document
output: references.bib
bibliography---
`r cite_r(pkgs = "tidyverse")`. Analyses were conducted with
This assumes there is a bib file of references called references.bib
that
contain the following entries.
@Manual{r,
= {R: A Language and Environment for Statistical Computing},
title = {{R Core Team}},
author = {R Foundation for Statistical Computing},
organization = {Vienna, Austria},
address = {2021},
year = {https://www.R-project.org/},
url
}
@Article{tidyverse,
= {Welcome to the {tidyverse}},
title = {Hadley Wickham and Mara Averick and Jennifer Bryan and Winston Chang and Lucy D'Agostino McGowan and Romain François and #' Garrett Grolemund and Alex Hayes and Lionel Henry and Jim Hester and Max Kuhn and Thomas Lin Pedersen and Evan Miller and Stephan Milton #' Bache and Kirill Müller and Jeroen Ooms and David Robinson and Dana Paige Seidel and Vitalie Spinu and Kohske Takahashi and Davis #' Vaughan and Claus Wilke and Kara Woo and Hiroaki Yutani},
author = {2019},
year = {Journal of Open Source Software},
journal = {4},
volume = {43},
number = {1686},
pages = {10.21105/joss.01686},
doi }
Examples
# cite R and the tidyverse
cite_r(pkgs = "tidyverse")
#> [1] "R version 4.3.0 with the tidyverse (v2.0.0) package [@r; @tidyverse]"
# cite R and the tidyverse, but text only
cite_r(pkgs = "tidyverse", add_citations = FALSE)
#> R version 4.3.0 with the tidyverse (v2.0.0) package
# only cite R
cite_r(pkgs = NULL)
#> [1] "R version 4.3.0 [@r]"