R "stats" citation for a scientific paper
Asked Answered
A

5

43

I analyzed my data using R package ‘stats’ (version 2.15.3). A reviewer asked me the right citation of this package and not only the common

R Core Team (2012). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL http://www.R-project.org/

Anyone know where i can find a valid citation to insert in my paper? Thanks

Argal answered 28/3, 2013 at 17:50 Comment(2)
Ask the reviewer if he/she has ever used R... a citation to the stats package is just useless. Maybe you shouldn't mention the stats package as such, but just plain R?Excrement
@caerolus -- Yes, exactly. To do otherwise is just inviting confusion. (Also no need to cite the 'base', 'graphics' and 'grDevices' packages as anything other than 'R' ;-).Arnica
S
76

The reviewer is wrong:

 citation("stats")

The ‘stats’ package is part of R.  To cite R in publications use:

  R Core Team (2013). R: A language and environment for statistical computing. R
  Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL
  http://www.R-project.org/.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {R: A Language and Environment for Statistical Computing},
    author = {{R Core Team}},
    organization = {R Foundation for Statistical Computing},
    address = {Vienna, Austria},
    year = {2013},
    note = {{ISBN} 3-900051-07-0},
    url = {http://www.R-project.org/},
  }

We have invested a lot of time and effort in creating R, please cite it when
using it for data analysis. See also ‘citation("pkgname")’ for citing R
packages.
Sucre answered 28/3, 2013 at 17:52 Comment(2)
But probably better follow caerolus and Josh O'Brien's advice above.Sucre
Note that, aside from the very first line of R textual output, the actual citations given by citation() and citation("base") and citation("stats") and citation("graphics") and citation("grDevices") are all the same.Fogdog
P
18

As hrbrmstr pointed out, a function to create a list of references of only loaded packages would come in handy. As he only showed us an example and not the function, I wrote one myself which I use very often in scientific analyses and papers (sometimes combined with R Markdown).

citations <- function(includeURL = TRUE, includeRStudio = TRUE) {
    if(includeRStudio == TRUE) {
        ref.rstudio <- RStudio.Version()$citation
        if(includeURL == FALSE) {
            ref.rstudio$url <- NULL;
        }
        print(ref.rstudio, style = 'text')
        cat('\n')
    }

    cit.list <- c('base', names(sessionInfo()$otherPkgs))
    for(i in 1:length(cit.list)) {
        ref <- citation(cit.list[i])
        if(includeURL == FALSE) {
            ref$url <- NULL;
        }
        print(ref, style = 'text')
        cat('\n')
    }
}

So, for example, after running

library(readr)
library(dplyr)
library(ggplot2)
library(knitr)

the function citations() will print:

RStudio Team (2016). RStudio: Integrated Development Environment for R. RStudio, Inc., Boston, MA. http://www.rstudio.com.

R Core Team (2017). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org.

Xie Y (2016). knitr: A General-Purpose Package for Dynamic Report Generation in R. R package version 1.15.1, http://yihui.name/knitr.

Xie Y (2015). Dynamic Documents with R and knitr, 2nd edition. Chapman and Hall/CRC, Boca Raton, Florida. ISBN 978-1498716963, http://yihui.name/knitr.

Xie Y (2014). “knitr: A Comprehensive Tool for Reproducible Research in R.” In Stodden V, Leisch F and Peng RD (eds.), Implementing Reproducible Computational Research. Chapman and Hall/CRC. ISBN 978-1466561595, http://www.crcpress.com/product/isbn/9781466561595.

Wickham H (2009). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. ISBN 978-0-387-98140-6, http://ggplot2.org.

Wickham H and Francois R (2016). dplyr: A Grammar of Data Manipulation. R package version 0.5.0, https://CRAN.R-project.org/package=dplyr.

Wickham H, Hester J and Francois R (2016). readr: Read Tabular Data. R package version 1.0.0, https://CRAN.R-project.org/package=readr.

Paedo answered 10/5, 2017 at 9:6 Comment(3)
That's a very slick and easy way to give proper attribution. Should this be a CRAN package or added to R?Sarisarid
Thanks! As far as I'm concerned, this should be a base function :) For now, you'll have to copy and paste this code and run it to load it into your environment.Paedo
great function!Modality
P
14

In our recent book, Data, Driven Security: Analysis, Visualization and Dashboards, my co-author and I did the R citation (in the frontmatter) but also got the publisher to let us give per-package credit as well:

enter image description here

We felt that it was important to ensure those that did the work got credit all the way 'round.

Purify answered 7/5, 2014 at 20:44 Comment(0)
S
7

There is now a grateful package that can be handy:

The goal of grateful is to make it very easy to cite the R packages used in any report or publication. By calling a single function, it will scan the project for R packages used and generate a document with citations in the desired output format (Word, PDF, HTML, Markdown). Importantly, these references can be formatted for a specific journal so that we can just paste them directly into the bibliography list of our manuscript or report.

https://github.com/Pakillo/grateful

If the package stats is loaded, the reference can be obtained by running:

library(grateful)
cite_packages()

—assuming grateful has already been installed by running:

library(devtools)
install_github("Pakillo/grateful")
Serpigo answered 17/10, 2017 at 2:52 Comment(0)
M
0

I like the solution by MS Berends but wanted a table with version numbers like this answer. I also wanted to get rid of the markdown produced by format(citation(pkg), style = 'text') so I could just easily copy-paste into MS Word.

require(pacman)
require(gt)
require(stringr)
require(dplyr)
get_package_citation_table <- function(){
  appendix_packages <- data.frame(Package = character(),
                                  Version = character(),
                                  Maintainer = character(),
                                  Citation = character())
  
  for (pkg in p_loaded()){
    appendix_packages <- appendix_packages %>% add_row(
      Package = pkg,
      Version = as.character(packageVersion(pkg)),
      Maintainer = maintainer(pkg),
      Citation = format(citation(pkg), style = 'text')
    )
  }
  appendix_packages <- appendix_packages %>% 
    add_row(
      Package = "RStudio",
      Version = as.character(RStudio.Version()$version),
      Maintainer = "",
      Citation = format(RStudio.Version()$citation, style = "text") 
    ) %>%
    add_row(
      Package = "R",
      Version = paste(version$major,version$minor, sep="."),
      Maintainer = "",
      Citation = format(citation(), style = "text")
    )
  
  appendix_packages %>%
    mutate( Citation = Citation %>% # strip out the markdown
              str_replace_all("_","") %>%
              str_replace_all("[*]", "") %>%
              str_replace_all("<URL:", "") %>%
              str_replace_all(">","")) %>% 
    arrange(Package)
  
}

t<- get_package_citation_table() 
t %>% gt()
Mccoy answered 25/3, 2021 at 23:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.