update.packages {utils} | R Documentation

## Download Packages from CRAN-like repositories

### Description

These functions can be used to automatically compare the version numbers of installed packages with the newest available version on the repositories and update outdated packages on the fly.

### Usage

    update.packages(lib.loc = NULL, repos = CRAN,
                    contriburl = contrib.url(repos, type),
                    CRAN = getOption("repos"),
                    method, instlib = NULL,
                    ask = TRUE, available = NULL, destdir = NULL,
                    installWithVers = FALSE, checkBuilt = FALSE,
                    type = getOption("pkgType"))

    available.packages(contriburl = contrib.url(getOption("repos")), method)

    CRAN.packages(CRAN = getOption("repos"), method,
                  contriburl = contrib.url(CRAN))

    old.packages(lib.loc = NULL, repos = CRAN,
                 contriburl = contrib.url(repos),
                 CRAN = getOption("repos"),
                 method, available = NULL, checkBuilt = FALSE)

    new.packages(lib.loc = NULL, repos = CRAN,
                 contriburl = contrib.url(repos),
                 CRAN = getOption("repos"),
                 method, available = NULL, ask = FALSE)

    download.packages(pkgs, destdir, available = NULL,
                      repos = CRAN,
                      contriburl = contrib.url(repos, type),
                      CRAN = getOption("repos"), method,
                      type = getOption("pkgType"))

    install.packages(pkgs, lib, repos = CRAN,
                     contriburl = contrib.url(repos, type),
                     CRAN = getOption("repos"),
                     method, available = NULL, destdir = NULL,
                     installWithVers = FALSE, dependencies = FALSE,
                     type = getOption("pkgType"))

    contrib.url(repos, type = getOption("pkgType"))

### Arguments

`lib.loc` | character vector describing the location of R library trees to search through (and update packages therein).
`repos` | character vector, the base URL(s) of the repositories to use, i.e., the URL of the CRAN master such as `"http://cran.r-project.org"` or its Statlib mirror, `"http://lib.stat.cmu.edu/R/CRAN"`. Can be `NULL` to install from local `.tar.gz` files.
`contriburl` | URL(s) of the contrib section of the repositories. Use this argument only if your CRAN mirror is incomplete, e.g., because you burned only the ‘`contrib`’ section on a CD. Overrides argument `repos`. Can be `NULL` to install from local `.tar.gz` files.
`CRAN` | character, an earlier way to specify `repos`.
`method` | Download method, see `download.file`.

`pkgs`

character vector of the short names of packages/bundles whose current versions should be downloaded from `CRAN`. If `repos = NULL`, a character vector of file paths of `.tar.gz` files. These can be source archives or binary package/bundle archive files (as created by `R CMD build --binary`). If this is a zero-length character vector, a listbox of available packages (including those contained in bundles) is presented where possible.

`destdir` | directory where downloaded packages are stored.
`available` | an object listing packages available at the repositories as returned by `CRAN.packages`.
`lib` | character vector giving the library directories where to install the packages. Recycled as needed.
`ask` | logical indicating whether to ask user before packages are actually downloaded and installed, or the character string `"graphics"`, which brings up a widget to allow the user to (de-)select from the list of packages which could be updated. The latter only works on systems with a GUI version of `select.list`, and is otherwise equivalent to `ask = TRUE`.
`installWithVers` | If `TRUE`, will invoke the install of the package such that it can be referenced by package version.
`checkBuilt` | If `TRUE`, a package built under an earlier minor version of R is considered to be ‘old’.
`instlib` | character string giving the library directory where to install the packages.
`dependencies` | logical indicating to also install uninstalled packages on which these packages depend/suggest/import (and so on recursively). Not used if `repos = NULL`. Can also be a character vector, a subset of `c("Depends", "Imports", "Suggests")`.
`type` | character, indicating the type of package to download and install. Possible values are `"source"` (the default except under the CRAN Mac OS X build), `"mac.binary"` and `"win.binary"` (which can be downloaded but not installed).

### Details

All of these functions work with the names of a package or bundle (and not the component packages of a bundle, except for `install.packages` if the repository provides the necessary information).

`CRAN.packages` returns a matrix of details corresponding to packages/bundles currently available in the `contrib` section of CRAN, the comprehensive R archive network. The current list of packages is downloaded over the internet (or copied from a local CRAN mirror). `available.packages` does the same for one or more repositories with a similar structure. Both return only packages whose version requirements are met by the running version of R.

`old.packages` compares the information from `available.packages` with that from `installed.packages` and reports installed packages/bundles that have newer versions on the repositories or, if `checkBuilt = TRUE`, that were built under an earlier minor version of R (for example built under 2.0.x when running R 2.1.1).

`new.packages` does the same comparison but reports uninstalled packages/bundles that are available at the repositories. It will also give warnings about incompletely installed bundles (provided the information is available) and bundles whose contents has changed. If `ask != FALSE` it asks which packages should be installed in the first element of `lib.loc`.

`download.packages` takes a list of package/bundle names and a destination directory, downloads the newest versions and saves them in `destdir`. If the list of available packages is not given as argument, it is obtained from repositories. If a repository is local, i.e., the URL starts with `"file:"`, then the packages are not downloaded but used directly. (Both `"file:"` and `"file://"` are allowed as prefixes to a file path.)

The main function of the set is `update.packages`. First a list of all packages/bundles found in `lib.loc` is created and compared with those available at the repostories. If `ask = TRUE` (the default) packages/bundles with a newer version are reported and for each one the user can specify if it should be updated. If so, the package sources are downloaded from the repositories and installed in the respective library path (or `instlib` if specified) using the R `INSTALL` mechanism.

`install.packages` can be used to install new packages/bundles. It takes a vector of names and a destination library, downloads the packages from the repositories and installs them. (If the library is omitted it defaults to the first directory in `.libPaths()`, with a warning if there is more than one.) An attempt is made to install the packages in an order that respects their dependencies. This does assume that all the entries in `lib` are on the default library path for installs (set by `R_LIBS`).

`contrib.url` adds the appropriate type-specific path within a repository to each URL in `repos`.

For `install.packages` and `update.packages`, `destdir` is the directory to which packages will be downloaded. If it is `NULL` (the default) a directory `downloaded_packages` of the session temporary directory will be used (and the files will be deleted at the end of the session).

If `repos` or `contriburl` is a vector of length greater than one, the newest version of the package is fetched from the first repository on the list within which it is found.

### Value

For `CRAN.packages` and `available.packages`, a matrix with one row per package/bundle, row names the package names and column names `"Package"`, `"Version"`, `"Priority"`, `"Bundle"`, `"Depends"`, `"Imports"`, `"Suggests"` `"Contains"` and `"Repository"`.
For `old.packages`, `NULL` or a matrix with one row per package/bundle, row names the package names and column names `"Package"`, `"LibPath"`, `"Installed"` (the version), `"Built"` (the version built under), `"ReposVer"` and `"Repository"`.
For `new.packages` a character vector of package/bundle names.
For `download.packages`, a two-column matrix of names and destination file names, for those packages/bundles successfully downloaded.
`install.packages` and `update.packages` have no return value.

### Warning

Not enough information is recorded to know if a bundle is completely installed, so a bundle is regarded as installed if any of its component packages is.

### Note

Some binary distributions of R have `INSTALL` in a separate bundle, e.g. an `R-devel` RPM. `install.packages` will give an error if called on such a system.

### See Also

`installed.packages`.

See `download.file` for how to handle proxies and other options to monitor file transfers.

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

[Package utils version 2.1.1 Index]