R语言install.packages函数帮助文档中英对照

第一部分:获取文档

已知函数名时,可以在Rstudio中输入help(“函数名”)获取该函数的帮助文档。
这里获取install.packages函数文档的代码:

help("install.packages")

这里写图片描述
从图中可以看到install.packages函数存在于{utils}工具包中。
另一种方法,已知包名utils时,可以通过包名utils查找到函数。获取帮助文档:help.start()
这里写图片描述
打开帮助文档页面,选择packages:
这里写图片描述
选择utils的install.packages函数:
这里写图片描述这里写图片描述


第二部分:文档剖析

install.packages {utils}
函数名 {包名}
Description:描述
Download and install packages from CRAN-like repositories or from local files.
从类似CRAN的存储库或本地文件下载并安装软件包。
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 whose current versions should be downloaded from the repositories.If repos = NULL, a character vector of file paths of ‘.zip’ files containing binary builds of packages. (http:// and file:// URLs are also accepted and the files will be downloaded and installed from local copies.) Source directories or file paths or URLs of archives may be specified with type = “source”, but some packages need suitable tools installed (see the ‘Details’ section).If this is missing or a zero-length character vector, a listbox of available packages is presented where possible in an interactive R session.
中文 字符向量,指向需要下载的包在存储库中当前版本对应的包名。如果repos参数值为空,则该字符向量对应着一个文件:默认存储库路径下已经存在的一个二进制zip文件(如果是从本地副本文件下载并安装,用“http://”或者“file://URL”Z作为字符向量参数也是被接受的)源目录或文件路径或URL需要使用type =“source”来特别指定,但某些软件包需要安装适配的工具(请参阅“详细信息”部分)。如果没有输入该参数或参数字符长度为0,在交互式R会话中尽可能的提供了可用软件包的列表。
lib character vector giving the library directories where to install the packages. Recycled as needed. If missing, defaults to the first element of .libPaths().
中文 字符向量,指向软件包的安装位置的库目录。根据需要回收。如果缺失,则默认为.libPaths()的第一个元素
repos character vector, the base URL(s) of the repositories to use, e.g., the URL of a CRAN mirror such as “https://cloud.r-project.org“. For more details on supported 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.
中文 字符向量,要使用的存储库的基本URL,例如诸如“https://cloud.r-project.org”之类的CRAN镜像的URL。 有关受支持的URL方案的更多详细信息,请参阅URL。参数为空时,可以从本地文件,目录或URL安装:如果长度为1,将通过pkgs的扩展来推断。
contriburl URL(s) of the contrib sections of the repositories. Use this argument if your repository mirror is incomplete, e.g., because you burned only the ‘contrib’ section on a CD, or only have binary packages. Overrides argument repos. Incompatible with type = “both”.
中文 存储库的contrib部分的URL。 如果您的存储库镜像不完整,请使用此参数,例如,因为您仅刻录了CD上的“contrib”部分,或者只刻录了二进制软件包。 覆盖参数回购。 与type =“both”不兼容。
method download method, see download.file. Unused if a non-NULL available is supplied.
中文 下载方法请参见download.file。 如果非NULL可用被支持,否则不可用。
available a matrix as returned by available.packages listing packages available at the repositories, or NULL when the function makes an internal call to available.packages. Incompatible with type = “both”.
中文 一个由available.packages返回的矩阵,列出存储库中可用的包,或者当函数对available.packages进行内部调用时返回NULL。 与type =“both”不兼容。
destdir directory where downloaded packages are stored. If it is NULL (the default) a subdirectory downloaded_packages of the session temporary directory will be used (and the files will be deleted at the end of the session).
中文 存放下载的软件包的目录。 如果它是NULL(默认),将使用会话临时目录的子目录download_packages(并且会话结束时删除文件)。
dependencies logical indicating whether to also install uninstalled packages which these packages depend on/link to/import/suggest (and so on recursively). Not used if repos = NULL. Can also be a character vector, a subset of c(“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. If this is not the case it is ignored, with a warning.The default, NA, means c(“Depends”, “Imports”, “LinkingTo”).TRUE means to use c(“Depends”, “Imports”, “LinkingTo”, “Suggests”) for pkgs and c(“Depends”, “Imports”, “LinkingTo”) for added dependencies: this installs all the packages needed to run pkgs, their examples, tests and vignettes (if the package author specified them correctly).In all of these, “LinkingTo” is omitted for binary packages.
中文
type character, indicating the type of package to download and install. Will be “source” except on Windows and some macOS builds: see the section on ‘Binary packages’ for those.
中文 字符,表示要下载和安装的软件包的类型。 除了Windows和一些macOS版本之外,将是“源代码”:请参阅“二进制软件包”部分。
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 are concatenated into a single string (separated by a space) and used as the value for the –configure-args flag in the call to R CMD INSTALL. If the character vector has names these are assumed to identify values for –configure-args for individual packages. This allows one to specify settings for an entire collection of packages which will be used if any of those packages are to be installed. (These settings can therefore be re-used and act as default settings.)A named list can be used also to the same effect, and that allows multi-element character strings for each package which are concatenated to a single string to be used as the value for –configure-args.
中文 字符向量
configure.vars (Used only for source installs.) Analogous to configure.args for flag –configure-vars, which is used to set environment variables 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 end of the package installation in addition to removing intermediate files.
中文 逻辑值,指示是否将–clean标志添加到对R CMD INSTALL的调用中。 除了删除中间文件之外,这有时用于在软件包安装结束时执行其他操作。
Ncpus the number of parallel processes to use for a parallel install of more than one source package. Values greater than one are supported if the make command specified by Sys.getenv(“MAKE”, “make”) accepts argument -k -j Ncpus.
中文 用于并行安装多个源代码包的并行进程数。 如果由Sys.getenv(“MAKE”,“make”)指定的make命令接受参数-k -j Ncpus,则支持大于1的值。
verbose a logical indicating if some “progress report” should be given.
中文 逻辑值,表明是否应该给出一些“进度报告”。
libs-only a logical value: should the –libs-only option be used to install only additional sub-architectures for source installs? (See also INSTALL_opts.) This can also be used on Windows to install just the DLL(s) from a binary package, e.g. to add 64-bit DLLs to a 32-bit install.
中文 逻辑值,应仅使用–libs-only选项来仅安装用于源安装的其他子体系结构? (另请参阅INSTALL_opts。)这也可以在Windows上用于从二进制包中仅安装DLL, 将64位DLL添加到32位安装中。
INSTALL_opts an optional character vector of additional option(s) to be passed to R CMD INSTALL for a source package install. E.g., c(“–html”, “–no-multiarch”).Can also be a named list of character vectors to be used as additional options, with names the respective package names.
中文 附加选项的可选字符向量,将被传递给R CMD INSTALL以进行源包安装。 例如,c(“ - html”,“–no-multiarch”)。也可以是用作附加选项的字符向量的命名列表,其名称为相应的软件包名称。
quiet logical: if true, reduce the amount of output.
中文 逻辑值,如果为true,则减少输出量。
keep_outputs a logical: if true, keep the outputs from installing source packages in the current working directory, with the names of the output files the package names with ‘.out’ appended. Alternatively, a character string giving the directory in which to save the outputs. Ignored when installing from local files.
中文 逻辑值,如果为true,则将源代码包的安装输出保留在当前工作目录中,输出文件的名称附带’.out’。 另外,还可以使用一个字符串,给出用于保存输出的目录。 从本地文件安装时忽略。

Details:细节
This is the main function to install packages. 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 message if there is more than one.) If lib is omitted or is of length one and is not a (group) writable directory, in interactive use the code offers to create a personal library tree (the first element of Sys.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 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 environment variable R_LIBS).

You are advised to run update.packages before install.packages to ensure that any already installed dependencies have their latest versions.
这是安装软件包的主要功能。 它需要一个名称矢量和一个目标库,从存储库下载软件包并安装它们。 (如果省略了库,它将缺省设置为.libPaths()中的第一个目录,如果有多个,则会显示一条消息。)如果lib被省略或长度为1并且不是(组)可写目录,则在交互 使用代码提供来创建个人库树(Sys.getenv的第一个元素(“R_LIBS_USER”))并在那里安装。 在Windows上检测可写目录是有问题的:请参阅“注释”部分。

对于从存储库进行安装,将尝试按照尊重其依赖关系的顺序安装软件包。 这确实假定lib中的所有条目都在安装的缺省库路径上(由环境变量R_LIBS设置)。

建议您在install.packages之前运行update.packages,以确保任何已安装的依赖项具有最新版本。

Binary packages:二进制包
This section applies only to platforms where binary packages are available: Windows and CRAN builds for macOS.

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

Possible values of type are (currently) “source”, “mac.binary”, “mac.binary.el-capitan” and “win.binary”: the appropriate binary type where supported can also be selected as “binary”.

For a binary install from a repository, the function checks for the availability of a source package on the same repository, and reports if the source package has a later version, or is available but no binary 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 binary files.

An alternative (and the current default) is “both” which means ‘use binary if available and current, otherwise try source’. The action if there are source packages which are preferred but may contain code which needs to be compiled is controlled by getOption(“install.packages.compile.from.source”). type = “both” will be silently changed to “binary” if either contriburl or available is specified.

Using packages with type = “source” always works provided the package contains no C/C++/Fortran code that needs compilation. Otherwise you will need to have installed the Rtools collection as described in the ‘R for Windows FAQ’ and you must have the PATH environment variable set up as required by Rtools.

For a 32/64-bit installation of R on Windows, a small minority of packages with compiled code need either INSTALL_opts = “–force-biarch” or INSTALL_opts = “–merge-multiarch” for a source installation. (It is safe to always set the latter when installing from a repository or tarballs, although it will be a little slower.)

When installing a binary package, install.packages will abort the install if it detects that the package is already installed and is currently in use. In some circumstances (e.g., multiple instances of R running at the same time and sharing a library) it will not detect a problem, but the installation may fail as Windows locks files in use.
本节仅适用于二进制软件包可用的平台:Windows和CRAN为macOS构建。

R软件包主要是作为源软件包分发的,但二进制软件包(对已安装软件包的打包)也是受支持的,Windows和CRAN最常用的类型是为macOS构建的。该功能可以通过从存储库下载文件或从本地文件安装任一类型。

类型的可能值是(当前)“source”,“mac.binary”,“mac.binary.el-capitan”和“win.binary”:支持的适当二进制类型也可以选择为“binary”。

对于来自存储库的二进制安装,该功能检查同一存储库上的源包的可用性,并报告源包是否具有更高版本,或者可用但没有二进制版本。该检查可以通过使用来抑制

选项(install.packages.check.source =“no”)

并且应该是如果存在仅包含二进制文件的部分存储库。

另一种(和当前的默认)是“两个”,这意味着’使用二进制文件如果可用和当前,否则尝试源’。如果存在首选的源代码包但可能包含需要编译的代码的操作由getOption(“install.packages.compile.from.source”)控制。如果指定了contriburl或available,则type =“both”将默默更改为“binary”。

如果程序包中不包含需要编译的C / C ++ / Fortran代码,那么使用type =“source”的包总是可以工作的。否则,您将需要按照’R for Windows常见问题解答’中所述安装Rtools集合,并且必须按照Rtools的要求设置PATH环境变量。

对于在Windows上安装R的32/64位版本,少数包含编译代码的包需要INSTALL_opts =“–force-biarch”或INSTALL_opts =“–merge-multiarch”来安装源代码。 (从存储库或tarball安装时总是设置后者是安全的,尽管它会稍微慢一些。)

安装二进制软件包时,如果安装包检测到软件包已安装且当前正在使用中,它将中止安装。在某些情况下(例如,R的多个实例同时运行并共享一个库)它不会检测到问题,但由于Windows锁定正在使用的文件,安装可能会失败。
Locking:锁定
There are various options for locking: these differ between source and binary installs.

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

For a macOS or Windows binary install, no locking is done by default. Setting argument lock to TRUE (it defaults to the value of getOption(“install.lock”, FALSE)) will use per-directory locking as described for source installs: if the value is “pkglock” per-package locking will be used.

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

Note that it is possible for the package installation to fail so badly that the lock directory is not removed: this inhibits any further installs to the library directory (or for –pkglock, of the package) until the lock directory is removed manually.
有各种锁定选项:这些选项在源安装和二进制安装之间有所不同。

默认情况下,对于源安装,通过在其中创建目录’00LOCK’来锁定库目录。这有两个目的:它可以防止任何其他进程同时安装到该库中,并用于存储错误恢复的任何先前版本的软件包。选项–pkglock提供更细粒度的锁定,为每个包创建一个单独的锁:这为并行安装提供了足够的自由度。在安装单个软件包时,每个软件包锁定是默认的,而当Ncpus> 1L时,每个软件包的锁定是多个软件包。最后锁定(和错误恢复)可以通过–no-lock来抑制。

对于macOS或Windows二进制安装,默认情况下不进行锁定。将参数锁设置为TRUE(默认值为getOption(“install.lock”,FALSE))将使用每个目录的锁定,如源安装所述:如果值为“pkglock”,则将使用每包锁定。

如果软件包锁定在libs_only = TRUE的Windows上使用,并且安装失败,则软件包将恢复到以前的状态。

请注意,软件包安装可能会出现如此严重的故障,以至于不会删除锁定目录:这将禁止进一步安装到库目录(或用于软件包的 - pkglock),直到手动删除锁定目录为止。

Parallel installs:并行安装
Parallel installs are attempted if pkgs has length greater than one and Ncpus > 1. It makes use of a parallel make, so the make specified (default make) when R was built must be capable of supporting make -j n: GNU make, dmake and pmake do, but Solaris make and older FreeBSD make do not: if necessary environment variable MAKE can be set for the current session to select a suitable make.

install.packages needs to be able to compute all the dependencies of pkgs from available, including if one element of pkgs depends indirectly on another. This means that if for example you are installing CRAN packages which depend on Bioconductor packages which in turn depend on CRAN packages, available needs to cover both CRAN and Bioconductor packages.
如果pkgs的长度大于1且Ncpus> 1,则尝试并行安装。它使用并行make,因此在构建R时必须能够支持make -jn:GNU make,dmake和pmake做的,但Solaris make和FreeBSD做的不做:如果必要,可以为当前会话设置环境变量MAKE来选择合适的make。

install.packages需要能够计算pkgs的所有依赖关系,包括pkgs的一个元素间接依赖于另一个元素。这意味着如果您正在安装依赖于Bioconductor软件包的CRAN软件包,而这些软件包依赖于CRAN软件包,则需要同时支持CRAN和Bioconductor软件包。

Note:注意
install.packages tries to detect if you have write permission on the library directories specified, but Windows reports unreliably. If there is only one library directory (the default), R tries to find out by creating a test directory, but even this need not be the whole story: you may have permission to write in a library directory but lack permission to write binary files (such as ‘.dll’ files) there. See the ‘R for Windows FAQ’ for workarounds.
install.packages会尝试检测您是否对指定的库目录具有写入权限,但Windows报告不可靠。如果只有一个库目录(缺省值),R会尝试通过创建一个测试目录来找出问题,但即使这样也不一定是完整的:您可能有权在库目录中编写代码,但缺少写入二进制文件的权限(如’.dll’文件)。有关解决方法,请参阅’R for Windows常见问题解答’。
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)

猜你喜欢

转载自blog.csdn.net/sinat_35187039/article/details/80239533