LoadandCite {repmis}R Documentation

Install, load, and cite R packages

Description

LoadandCite can install and load R packages as well as automatically generate a BibTeX file citing the packages.

Usage

LoadandCite(pkgs = NULL, versions = NULL, Rversion = NULL,
  bibtex = TRUE, style = "plain", tweak = TRUE, install = FALSE,
  file = NULL, repos = NULL, lib = NULL)

Arguments

pkgs

a character vector of R package names. If pkgs = NULL then LoadandCite only cites the non-base packages in the current session. It does not load or install any packages.

versions

character vector of package version numbers to install. Only works if install = TRUE. The order must match the order of package names in pkgs.

Rversion

a character string specifying a particular R version. If the version of R currently running differs from Rversion LoadandCite a warning will be given. This argument is for replication purposes.

bibtex

logical. If TRUE than a BibTeX formatted citation file is created. If FALSE than the citations are returned as plain text.

style

character string indicating stylistic elements to add to the citations. Currently supports 'plain', i.e. no special formatting and 'JSS' to match the BibTeX style for the Journal of Statistical Software (see http://www.jstatsoft.org/style).

tweak

logical. Whether to fix some known problems in the citations, especially non-standard format of authors.

install

a logical option for whether or not to install the packages. The default is install = FALSE.

file

the name of the BibTeX file you want to create. If file = NULL then the packages are loaded, but no BibTeX file is created.

repos

character vector specifying which repository to download packages from. Only relevant if install = TRUE and versions are not specified. If repos = NULL, automatically reads user defined repository (via options), but defaults to repos = "http://cran.us.r-project.org" if repos is not set.

lib

character vector giving the library directories where to install the packages. Recycled as needed. If NULL, defaults to the first element of .libPaths(). Only relevant if install = TRUE.

Details

The command can install R packages, load them, and create a BibTeX file that can be used to cite the packages in a LaTeX or similar document. It can be useful to place this command in a knitr code chunk at the beginning of a reproducible research document. Note: the command will overwrite existing files with the same name as file, so it is generally a good idea to create a new BibTeX file with LoadandCite.

Source

Gandrud, Christopher (2013). Automating R Package Citations in Reproducible Research Documents. SSRN. This function is partially based on: https://gist.github.com/3710171. It also builds on code from knitr's write_bib. See: Y. Xie. knitr: A general-purpose package for dynamic report generation in R, 2013. URL http://CRAN.R-project.org/package=knitr. R package version 1.5. Note that it does not formally depend on knitr so that knitr can be included in LoadandCite so that it is possible to install old versions of that package.

See Also

write_bib, install.packages, and library

Examples

# Create vector of package names
## In this example you need to have the packages installed aready.
PackNames <- "repmis"
# Load the packages and create a BibTeX file
LoadandCite(pkgs = PackNames, file = 'PackageCites.bib', style = 'JSS')
## Not run: 
# Install, load, and cite specific package versions
# dontrun due to CRAN restrictions
Names <- c("e1071", "gtools")
Vers <- c("1.6", "2.6.1")
LoadandCite(pkgs = Names, versions = Vers, install = TRUE,
             file = "PackageCites.bib")

## End(Not run)

[Package repmis version 0.5 Index]