install.packages: Install Packages from Repositories or Local Files (2024)

install.packagesR Documentation

Description

Download and install packages from CRAN-like repositories or fromlocal files.

Usage

install.packages(pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos, type), method, available = NULL, destdir = NULL, dependencies = NA, type = getOption("pkgType"), configure.args = getOption("configure.args"), configure.vars = getOption("configure.vars"), clean = FALSE, Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"), libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE, ...)

Arguments

pkgs

character vector of the names of packages whosecurrent versions should be downloaded from the repositories.

If repos = NULL, a character vector of file paths,

on windows,

file paths of ‘.zip’ files containing binary builds ofpackages. (http:// and file:// URLs are also acceptedand the files will be downloaded and installed from local copies.)Source directories or file paths or URLs of archives may bespecified with type = "source", but some packages needsuitable tools installed (see the ‘Details’ section).

On Unix-alikes,

these file paths can be source directories or archivesor binary package archive files (as created by R CMD build --binary). (http:// and file:// URLs are alsoaccepted and the files will be downloaded and installed from localcopies.) On a CRAN build of R for macOS these can be ‘.tgz’files containing binary package archives.Tilde-expansion will be done on file paths.

If this is missing, a listbox ofavailable packages is presented where possible in an interactive Rsession.

lib

character vector giving the library directories where toinstall the packages. Recycled as needed. If missing, defaults tothe first element of .libPaths().

repos

character vector, the base URL(s) of the repositoriesto use, e.g., the URL of a CRAN mirror such as"https://cloud.r-project.org". For more details onsupported URL schemes see url.

Can be NULL to install from local files, directories or URLs:this will be inferred by extension from pkgs if of length one.

contriburl

URL(s) of the contrib sections of the repositories. Use thisargument if your repository mirror is incomplete, e.g., becauseyou burned only the ‘contrib’ section on a CD, or only havebinary packages. Overrides argument repos.Incompatible with type = "both".

method

download method, see download.file. Unused ifa non-NULL available is supplied.

available

a matrix as returned by available.packageslisting packages available at the repositories, or NULL whenthe function makes an internal call to available.packages.Incompatible with type = "both".

destdir

directory where downloaded packages are stored. If it isNULL (the default) a subdirectorydownloaded_packages of the session temporarydirectory will be used (and the files will be deletedat the end of the session).

dependencies

logical indicating whether to also installuninstalled packages which these packages depend on/linkto/import/suggest (and so on recursively).Not used if repos = NULL.Can also be a character vector, a subset ofc("Depends", "Imports", "LinkingTo", "Suggests", "Enhances").

Only supported if lib is of length one (or missing),so it is unambiguous where to install the dependent packages. Ifthis is not the case it is ignored, with a warning.

The default, NA, meansc("Depends", "Imports", "LinkingTo").

TRUE means to usec("Depends", "Imports", "LinkingTo", "Suggests") forpkgs andc("Depends", "Imports", "LinkingTo") for added dependencies:this installs all the packages needed to run pkgs, theirexamples, tests and vignettes (if the package author specified themcorrectly).

In all of these, "LinkingTo" is omitted for binary packages.

type

character, indicating the type of package to download andinstall. Will be "source" except on Windows and some macOSbuilds: see the section on ‘Binary packages’ for those.

configure.args

(Used only for source installs.) A character vector or a named list.If a character vector with no names is supplied, the elements areconcatenated into a single string (separated by a space) and used asthe value for the --configure-args flag in the call toR CMD INSTALL. If the character vector has names theseare assumed to identify values for --configure-args forindividual packages. This allows one to specify settings for anentire collection of packages which will be used if any of thosepackages are to be installed. (These settings can therefore bere-used and act as default settings.)

A named list can be used also to the same effect, and thatallows multi-element character strings for each packagewhich are concatenated to a single string to be used as thevalue for --configure-args.

configure.vars

(Used only for source installs.) Analogous to configure.argsfor flag --configure-vars, which is used to set environmentvariables for the configure run.

clean

a logical value indicating whether to add the--clean flag to the call to R CMD INSTALL.This is sometimes used to perform additional operations at the endof the package installation in addition to removing intermediate files.

Ncpus

the number of parallel processes to use for a parallelinstall of more than one source package. Values greater than oneare supported if the make command specified bySys.getenv("MAKE", "make") accepts argument-k -j Ncpus.

verbose

a logical indicating if some “progress report” should be given.

libs_only

a logical value: should the --libs-only option be used toinstall only additional sub-architectures for source installs? (See alsoINSTALL_opts.) This can also be used on Windows to installjust the DLL(s) from a binary package, e.g. to add 64-bitDLLs to a 32-bit install.

INSTALL_opts

an optional character vector of additional option(s) to be passed toR CMD INSTALL for a source package install. E.g.,c("--html", "--no-multiarch", "--no-test-load").

Can also be a named list of character vectors to be used asadditional options, with names the respective package names.

quiet

logical: if true, reduce the amount of output. This is notpassed to available.packages() in case that is called, onpurpose.

keep_outputs

a logical: if true, keep the outputs from installing source packagesin the current working directory, with the names of the output filesthe package names with ‘.out’ appended. Alternatively, acharacter string giving the directory in which to save the outputs.Ignored when installing from local files.

...

Arguments to be passed to download.file,available.packages, or to the functions for binaryinstalls on macOS and Windows (which accept an argument "lock":see the section on ‘Locking’).

Details

This is the main function to install packages. It takes a vector ofnames and a destination library, downloads the packages from therepositories and installs them. (If the library is omitted itdefaults to the first directory in .libPaths(), with a messageif there is more than one.) If lib is omitted or is of lengthone and is not a (group) writable directory, in interactive use thecode offers to create a personal library tree (the first element ofSys.getenv("R_LIBS_USER")) and install there.

Detection of a writable directory is problematic on Windows: see the‘Note’ section.

For installs from a repository an attempt is made to install thepackages in an order that respects their dependencies. This doesassume that all the entries in lib are on the default librarypath for installs (set by environment variable R_LIBS).

You are advised to run update.packages beforeinstall.packages to ensure that any already installeddependencies have their latest versions.

Value

Invisible NULL.

Binary packages

This section applies only to platforms where binary packages areavailable: Windows and CRAN builds for macOS.

R packages are primarily distributed as source packages, butbinary packages (a packaging up of the installed package) arealso supported, and the type most commonly used on Windows and by theCRAN builds for macOS. This function can install either type, either bydownloading a file from a repository or from a local file.

Possible values of type are (currently) "source","mac.binary", and"win.binary": the appropriate binary type where supported canalso be selected as "binary".

For a binary install from a repository, the function checks for theavailability of a source package on the same repository, and reportsif the source package has a later version, or is available but nobinary version is. This check can be suppressed by using

 options(install.packages.check.source = "no")

and should be if there is a partial repository containing only binaryfiles.

An alternative (and the current default) is "both" which means‘use binary if available and current, otherwise trysource’. The action if there are source packages which are preferredbut may contain code which needs to be compiled is controlled bygetOption("install.packages.compile.from.source").type = "both" will be silently changed to "binary" ifeither contriburl or available is specified.

Using packages with type = "source" always works provided thepackage contains no C/C++/Fortran code that needs compilation.Otherwise,

on Windows

you will need to have installed the Rtoolscollection as described in the ‘R for Windows FAQ’ andyou must have the PATH environment variable set up as requiredby Rtools.

For a 32/64-bit installation of R on Windows, a small minority ofpackages with compiled code need either INSTALL_opts = "--force-biarch" or INSTALL_opts = "--merge-multiarch" for asource installation. (It is safe to always set the latter wheninstalling from a repository or tarballs, although it will be a littleslower.)

When installing a package on Windows, install.packages will abortthe install if it detects that the package is already installed and iscurrently in use. In some circ*mstances (e.g., multiple instances ofR running at the same time and sharing a library) it will not detect aproblem, but the installation may fail as Windows locks files in use.

On Unix-alikes,

when the package contains C/C++/Fortran codethat needs compilation, on macOS you need to have installed the‘Command-line tools for Xcode’ (see the‘R Installation and Administration’ manual) and if neededby the package a Fortran compiler, and have them in your path.

Locking

There are various options for locking: these differ between source andbinary installs.

By default for a source install, the library directory is‘locked’ by creating a directory ‘00LOCK’ within it. Thishas two purposes: it prevents any other process installing into thatlibrary concurrently, and is used to store any previous version of thepackage to restore on error. A finer-grained locking is provided bythe option --pkglock which creates a separate lock for eachpackage: this allows enough freedom for parallelinstallation. Per-package locking is the default when installing asingle package, and for multiple packages when Ncpus > 1L.Finally locking (and restoration on error) can be suppressed by--no-lock.

For a macOS binary install, no locking is done by default. Settingargument lock to TRUE (it defaults to the value ofgetOption("install.lock", FALSE)) will use per-directorylocking as described for source installs. For Windows binary install,per-directory locking is used by default (lock defaults to thevalue of getOption("install.lock", TRUE)). If the value is"pkglock" per-package locking will be used.

If package locking is used on Windows with libs_only = TRUE andthe installation fails, the package will be restored to its previousstate.

Note that it is possible for the package installation to fail so badlythat the lock directory is not removed: this inhibits any furtherinstalls to the library directory (or for --pkglock, of thepackage) until the lock directory is removed manually.

Parallel installs

Parallel installs are attempted if pkgs has length greater thanone and Ncpus > 1. It makes use of a parallel make,so the make specified (default make) when R wasbuilt must be capable of supporting make -j n: GNU make,dmake and pmake do, but Solaris make andolder FreeBSD make do not: if necessary environment variableMAKE can be set for the current session to select a suitablemake.

install.packages needs to be able to compute all thedependencies of pkgs from available, including if oneelement of pkgs depends indirectly on another. This means thatif for example you are installing CRAN packages which dependon Bioconductor packages which in turn depend on CRANpackages, available needs to cover both CRAN andBioconductor packages.

Timeouts

A limit on the elapsed time for each call to R CMD INSTALL(so for source installs) can be set via environment variable_R_INSTALL_PACKAGES_ELAPSED_TIMEOUT_: in seconds (or in minutesor hours with optional suffix m or h, suffix sbeing allowed for the default seconds) with 0 meaning no limit.

For non-parallel installs this is implemented via thetimeout argument of system2: for parallelinstalls via the OS's timeout command. (The onetested is from GNU coreutils, commonly available on Linux butnot other Unix-alikes. If no such command is available the timeoutrequest is ignored, with a warning.) For parallel installs aError 124 message from make indicates that timeoutoccurred.

Timeouts during installation might leave lock directories behind andnot restore previous versions.

Version requirements on source installs

If you are not running an up-to-date version of R you may see amessage like

 package 'RODBC' is not available (for R version 3.5.3)

One possibility is that the package is not available in any of theselected repositories; another is that is available but only forcurrent or recent versions of R. For CRAN packages takea look at the package's CRAN page (e.g.,https://cran.r-project.org/package=RODBC). If that indicates inthe Depends field a dependence on a later version of R youwill need to look in the Old sources section and select the URLof a version of comparable age to your R. Then you can supply thatURL as the first argument of install.packages(): you mayneed to first manually install its dependencies.

For other repositories, using available.packages(filters = "OS_type")[pkgname, ] will show if the package is availablefor any R version (for your OS).

Note

On Unix-alikes:

Some binary distributions of R have INSTALL in a separatebundle, e.g. an R-devel RPM. install.packages willgive an error if called with type = "source" on such a system.

Some binary Linux distributions of R can be installed on a machinewithout the tools needed to install packages: a possible remedy is todo a complete install of R which should bring in all those tools asdependencies.

On Windows:

install.packages tries to detect if you have write permissionon the library directories specified, but Windows reports unreliably.If there is only one library directory (the default), R tries tofind out by creating a test directory, but even this need not be thewhole story: you may have permission to write in a library directorybut lack permission to write binary files (such as ‘.dll’ files)there. See the ‘R for Windows FAQ’ for workarounds.

See Also

update.packages,available.packages,download.packages,installed.packages,contrib.url.

See download.file for how to handle proxies andother options to monitor file transfers.

untar for manually unpacking source package tarballs.

INSTALL, REMOVE, remove.packages,library, .packages, read.dcf

The ‘R Installation and Administration’ manual for how toset up a repository.

Examples

## Not run: ## A Linux example for Fedora's layout of udunits2 headers.install.packages(c("ncdf4", "RNetCDF"), configure.args = c(RNetCDF = "--with-netcdf-include=/usr/include/udunits2"))## End(Not run)
install.packages: Install Packages from Repositories or Local Files (2024)
Top Articles
Unreal Healthy Chicken Waldorf Salad Recipe | Nutrition in the Kitch
29 Healthy And Easy Spiralizer Recipes (+Tips)
Matgyn
Craigslist St. Paul
Unit 30 Quiz: Idioms And Pronunciation
Can ETH reach 10k in 2024?
Housing Intranet Unt
4Chan Louisville
Koop hier ‘verloren pakketten’, een nieuwe Italiaanse zaak en dit wil je ook even weten - indebuurt Utrecht
Chicken Coop Havelock Nc
Kinkos Whittier
Oro probablemente a duna Playa e nomber Oranjestad un 200 aña pasa, pero Playa su historia ta bay hopi mas aña atras
The fabulous trio of the Miller sisters
Lima Funeral Home Bristol Ri Obituaries
Buff Cookie Only Fans
Apne Tv Co Com
Louisiana Sportsman Classifieds Guns
Mflwer
Weather Rotterdam - Detailed bulletin - Free 15-day Marine forecasts - METEO CONSULT MARINE
Invert Clipping Mask Illustrator
Pretend Newlyweds Nikubou Maranoshin
Cta Bus Tracker 77
Craigslist Pearl Ms
Doki The Banker
Wics News Springfield Il
Sam's Club Gas Price Hilliard
1145 Barnett Drive
Dove Cremation Services Topeka Ks
Harrison County Wv Arrests This Week
Criterion Dryer Review
Democrat And Chronicle Obituaries For This Week
Kaliii - Area Codes Lyrics
Uno Fall 2023 Calendar
Proto Ultima Exoplating
Devargasfuneral
Atlantic Broadband Email Login Pronto
Helloid Worthington Login
42 Manufacturing jobs in Grayling
Telegram update adds quote formatting and new linking options
ATM Near Me | Find The Nearest ATM Location | ATM Locator NL
Pinellas Fire Active Calls
Cranston Sewer Tax
Wayne State Academica Login
Sukihana Backshots
Craigslist en Santa Cruz, California: Tu Guía Definitiva para Comprar, Vender e Intercambiar - First Republic Craigslist
Tripadvisor Vancouver Restaurants
Centimeters to Feet conversion: cm to ft calculator
Darkglass Electronics The Exponent 500 Test
Sc Pick 3 Past 30 Days Midday
The Plug Las Vegas Dispensary
2121 Gateway Point
E. 81 St. Deli Menu
Latest Posts
Article information

Author: Fr. Dewey Fisher

Last Updated:

Views: 6365

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Fr. Dewey Fisher

Birthday: 1993-03-26

Address: 917 Hyun Views, Rogahnmouth, KY 91013-8827

Phone: +5938540192553

Job: Administration Developer

Hobby: Embroidery, Horseback riding, Juggling, Urban exploration, Skiing, Cycling, Handball

Introduction: My name is Fr. Dewey Fisher, I am a powerful, open, faithful, combative, spotless, faithful, fair person who loves writing and wants to share my knowledge and understanding with you.