我的理解是它将取决于.libPaths()的顺序.这是来自的代码library
if (!missing(package)) {
if (is.null(lib.loc))
lib.loc <- .libPaths()
lib.loc <- lib.loc[file.info(lib.loc)$isdir %in% TRUE]
# >>>> snipped code
newpackage <- is.na(match(pkgname, search()))
if (newpackage) {
pkgpath <- find.package(package, lib.loc, quiet = TRUE,
verbose = verbose)
if (length(pkgpath) == 0L) {
# snipped
Run Code Online (Sandbox Code Playgroud)
这是来自帮助页面 find.package
Details
find.package returns path to the locations where the given packages are found.
If lib.loc is NULL, then attached packages are searched before the libraries.
If a package is found more than once, the first match is used.
Run Code Online (Sandbox Code Playgroud)
如果有多个实例,那么根据我对find.package代码的读取应该有一个警告(除非你将"verbose"设置为FALSE):
if (length(paths) > 1L) {
paths <- paths[1L]
if (verbose)
warning(gettextf("package %s found more than once,\n
using the one found in %s",
sQuote(pkg), sQuote(paths)), domain = NA)
Run Code Online (Sandbox Code Playgroud)
正如其他人已经说过的那样,.libPaths()搜索顺序问题就是为什么我们设置它以便首先搜索本地包作为发行版本,特别是Debian stable或Ubuntu版本未更新,更有可能更老.
在文件/etc/R/Renviron设置中对此效果有评论:
# edd Apr 2003 Allow local install in /usr/local, also add a directory for
# Debian packaged CRAN packages, and finally the default dir
# edd Jul 2007 Now use R_LIBS_SITE, not R_LIBS
R_LIBS_SITE=${R_LIBS_SITE-'/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library'}
Run Code Online (Sandbox Code Playgroud)
因此,用户设置的值R_LIBS_SITE将优先,否则使用此处显示的值.