shelf: Attach packages to the search path, installing them from...

Description Usage Arguments Details Value Examples

View source: R/exported_functions.R

Description

Attach packages to the search path, installing them from CRAN, GitHub, or Bioconductor if needed

Usage

1
2
3
4
5
6
7
8
9
shelf(
  ...,
  lib = NULL,
  update_all = FALSE,
  quiet = FALSE,
  ask = TRUE,
  cran_repo = getOption("repos"),
  bioc_repo = character()
)

Arguments

...

(Names) Packages as bare names. If the package is from GitHub, include both the username and package name as UserName/package (see examples).

lib

(Character) By R convention, packages are installed to the first folder in your library search path (lib_paths()). Here, you can set a specific folder to install new packages to instead. If the folder doesn't exist, you will be prompted to create it if ask = TRUE, otherwise it will be silently created. Can be an absolute or relative path. Tilde expansion is performed on the input, but wildcard expansion (globbing) is not. If lib has more than one element, only the first one will be kept. See the 'Details' section below for more information.

update_all

(Logical) If TRUE, the packages will be re-installed even if they are already in your library.

quiet

(Logical) If TRUE, suppresses most warnings and messages.

ask

(Logical) If TRUE, and lib points to a folder that doesn't exist, ask before creating the folder. If FALSE, the folder will be created silently.

cran_repo

(Character) In RStudio, a default CRAN repo can be set via Options > Packages > Default CRAN Mirror). Otherwise, provide the URL to CRAN or one of its mirrors. If an invalid URL is given, defaults to https://cran.r-project.org.

bioc_repo

(Character) If you use Bioconductor, you can set the repo URLs for it here. Defaults to Bioconductor's defaults (view them with BiocInstaller::biocinstallRepos()).

Details

You may choose to organise your library into folders to hold packages for different tasks or projects. If you specify a lib folder, it will be created (if needed) and attached to the package search path. R will look for packages by working through the package search path in order. You can view the folders that are on this path by calling lib_paths() with no arguments.

If you specify a new lib and use the argument update_all = TRUE to force an already-installed package to reinstall, a new copy of that package will be made in lib and then loaded from there. This means that you can potentially have several copies of the same package across many folders on your machine, each a different version. This allows you to maintain a different library folder for different projects, so that updated packages in Project B will not affect the package versions you rely on for Project A.

Value

Invisibly returns a named logical vector, where the names are the packages requested in ... and TRUE means that the package was successfully installed and attached.

Examples

1
2
3
4
5
6
7
8
shelf(fortunes, DesiQuintans/emptyRpackage, cowsay, lib = tempdir(), update_all = TRUE)

# shelf() returns invisibly; bind its output to a variable or access the .Last.value.

print(.Last.value)

#> fortunes emptyRpackage        cowsay 
#>     TRUE          TRUE          TRUE 

librarian documentation built on July 12, 2021, 5:07 p.m.