Add citations to R and R packages in an R Markdown report.
cite_r(pkgs = c("tidyverse", "gtsummary"), add_citations = TRUE)
character vector of package names to cite. Default is
c("tidyverse", "gtsummary")
. NULL
is acceptable.
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 the pkgs=
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'.
Below is an example how the cite_r()
function would be used in an R
Markdown report.
---
: html_document
output: references.bib
bibliography---
`r bstfun::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 }
# cite R and the tidyverse
cite_r(pkgs = "tidyverse")
#> [1] "R version 4.2.2 with the tidyverse (v1.3.2) package [@r; @tidyverse]"
# cite R and the tidyverse, but text only
cite_r(pkgs = "tidyverse", add_citations = FALSE)
#> R version 4.2.2 with the tidyverse (v1.3.2) package
# only cite R
cite_r(pkgs = NULL)
#> [1] "R version 4.2.2 [@r]"