library(base)
library()所属R语言包:base
Loading and Listing of Packages
载入和上市的软件包
译者:生物统计家园网 机器人LoveR
描述----------Description----------
library and require load add-on packages.
library和require加载附加软件包。
用法----------Usage----------
library(package, help, pos = 2, lib.loc = NULL,
character.only = FALSE, logical.return = FALSE,
warn.conflicts = TRUE, quietly = FALSE,
keep.source = getOption("keep.source.pkgs"),
verbose = getOption("verbose"))
require(package, lib.loc = NULL, quietly = FALSE,
warn.conflicts = TRUE,
keep.source = getOption("keep.source.pkgs"),
character.only = FALSE)
参数----------Arguments----------
参数:package, help
the name of a package, given as a name or literal character string, or a character string, depending on whether character.only is FALSE (default) or TRUE).
包名称或文字字符串,或一个字符串,根据名称是否character.only是FALSE(默认)或TRUE)。
参数:pos
the position on the search list at which to attach the loaded package. Can also be the name of a position on the current search list as given by search().
在搜索列表中的位置,在附加装包。也可以对当前的搜索列表中的位置由search()的名称。
参数:lib.loc
a character vector describing the location of R library trees to search through, or NULL. The default value of NULL corresponds to all libraries currently known to .libPaths(). Non-existent library trees are silently ignored.
字符向量描述R库树的位置,通过搜索,或NULL。默认值NULL.libPaths()目前已知的所有库。不存在库的树木被忽略掉。
参数:character.only
a logical indicating whether package or help can be assumed to be character strings.
逻辑表明是否package或help可以假定为字符串。
参数:logical.return
logical. If it is TRUE, FALSE or TRUE is returned to indicate success.
逻辑。如果是的话TRUE,FALSE或TRUE返回表示成功。
参数:warn.conflicts
logical. If TRUE, warnings are printed about conflicts from attaching the new package, unless that package contains an object .conflicts.OK. A conflict is a function masking a function, or a non-function masking a non-function.
逻辑。如果TRUE“警告印约conflicts附加新的软件包,除非该软件包包含一个对象.conflicts.OK。冲突是一个函数,屏蔽功能,或无功能,掩盖了非功能。
参数:keep.source
logical. Now ignored. This argument does not apply to packages using lazy-loading: whether they have kept source is determined when they are installed.
逻辑。现在被忽略。这种说法并不适用于使用延迟加载的包:他们是否不断源在安装时确定。
参数:verbose
a logical. If TRUE, additional diagnostics are printed.
一个逻辑。如果TRUE,印有额外的诊断。
参数:quietly
a logical. If TRUE, no message confirming package loading is printed, and most often, no errors/warnings are printed if package loading fails.
一个逻辑。如果TRUE,没有消息证实包加载印,最经常的是,如果没有错误/警告印包加载失败。
Details
详情----------Details----------
library(package) and require(package) both load the package with name package. require is designed for use inside other functions; it returns FALSE and gives a warning (rather than an error as library() does by default) if the package does not exist. Both functions check and update the list of currently loaded packages and do not reload a package which is already loaded. (Furthermore, if the package has a namespace and a name space of that name is already loaded, they work from the existing namespace rather than reloading from the file system. If you want to reload such a package, call detach(unload = TRUE) or unloadNamespace first.)
library(package)和require(package)名package都加载包。 require专为内部使用等功能,它返回FALSE“给出了一个警告(而不是作为错误library()不默认)如果包不存在。这两个函数的检查和更新当前加载的软件包列表,不重新载入一个已经加载的包。 (此外,如果包有一个命名空间,已经加载了这个名字的名字空间,他们的工作,从现有的命名空间,而不是从文件系统重装。如果你想重载这样的包,调用detach(unload = TRUE) unloadNamespace。)
To suppress messages during the loading of packages use suppressPackageStartupMessages: this will suppress all messages from R itself but not necessarily all those from package authors.
压制在包加载的消息,请使用suppressPackageStartupMessages:这将抑制R本身的所有邮件,但不一定所有那些从包作者。
If library is called with no package or help argument, it lists all available packages in the libraries specified by lib.loc, and returns the corresponding information in an object of class "libraryIQR". The structure of this class may change in future versions. In earlier versions of R, only the names of all available packages were returned; use .packages(all = TRUE) for obtaining these. Note that installed.packages() returns even more information.
library如果被称为没有package或help的说法,它列出在lib.loc指定的库的所有可用的软件包,并返回相应的信息在一个类的对象 "libraryIQR"。这个类的结构,在未来的版本中可能会改变。在研发的早期版本中,只有所有可用的软件包的名字被退回;使用.packages(all = TRUE)为获取这些。注意installed.packages()返回更详细的信息。
library(help = somename) computes basic information about the package somename, and returns this in an object of class "packageInfo". The structure of this class may change in future versions. When used with the default value (NULL) for lib.loc, the attached packages are searched before the libraries.
library(help = somename)关于包somename计算的基本信息,并返回一个对象类"packageInfo"。这个类的结构,在未来的版本中可能会改变。默认值(NULL)lib.loc使用时,附加的软件包库前搜索。
In versions of R prior to 2.14.0, a .First.lib function would be called when a package without a namespace was attached. As of 2.14.0, all functions have namespaces; see .onLoad for current behaviour, and "Writing R Extensions" for a description of the older mechanism.
在2.14.0之前版本的R,.First.lib函数将被调用时没有命名空间的包被重视。为2.14.0,所有的功能有命名空间;看到.onLoad目前的行为,并写R扩展“的旧机制的描述。
值----------Value----------
Normally library returns (invisibly) the list of attached packages, but TRUE or FALSE if logical.return is TRUE. When called as library() it returns an object of class "libraryIQR", and for library(help=), one of class "packageInfo".
通常情况下,library回报(不可见)的附加软件包的列表,但TRUE或FALSE如果logical.return是TRUE的。当library()调用,它返回一个类的对象"libraryIQR",library(help=)类"packageInfo"之一。
require returns (invisibly) a logical indicating whether the required package is available. (Before R 2.12.0 it could also fail with an error.)
require回报(不可见)的逻辑表示所需的软件包是否可用。 (它之前ŕ2.12.0可能也失败,错误。)
牌照----------Licenses----------
Some packages have restrictive licenses, and as from R 2.11.0 there is a mechanism to ensure that users are aware of such licenses. If getOption("checkPackageLicense") == TRUE, then at first use of a package with a not-known-to-be-FOSS (see below) license the user is asked to view and accept the license: a list of accepted licenses is stored in file "~/.R/licensed". In a non-interactive session it is an error to use such a package whose license has not already been accepted.
一些包有限制牌照,并从R 2.11.0是一个机制,以确保用户意识到这类牌照。如果getOption("checkPackageLicense") == TRUE,然后在第一次使用没有已知的是源码(见下文)的用户会被要求查看并接受许可执照:公认的牌照名单存储在一个文件包“~/.R/licensed。在非交互式会话,它是一个错误,使用这样一个包,其许可证尚未接受。
Free or Open Source Software (FOSS, e.g., http://en.wikipedia.org/wiki/FOSS) packages are determined by the same filters used by available.packages but applied to just the current package, not its dependencies.
免费或开放源码软件(源码,例如,http://en.wikipedia.org/wiki/FOSS)包确定available.packages但只是当前包,而不是它的依赖相同的过滤器。
There can also be a site-wide file "R_HOME/etc/licensed.site" of packages (one per line).
也可以是站点范围的文件R_HOME/etc/licensed.site包(每行一个)。
形式化方法----------Formal methods----------
library takes some further actions when package methods is attached (as it is by default). Packages may define formal generic functions as well as re-defining functions in other packages (notably base) to be generic, and this information is cached whenever such a package is loaded after methods and re-defined functions (implicit generics) are excluded from the list of conflicts. The caching and check for conflicts require looking for a pattern of objects; the search may be avoided by defining an object .noGenerics (with any value) in the package. Naturally, if the package does have any such methods, this will prevent them from being used.
library需要一些进一步的行动时,包methods连接(因为它是默认的)。包可能会确定正式的通用功能,以及在其他包(如著名的base)是通用的,这个信息缓存时,这样的包加载后methods和重新定义的函数的重新定义功能(隐式泛型)被排除冲突列表。缓存和检查的冲突需要寻找一个对象的模式;搜索可避免包中定义对象.noGenerics(任何值)。当然,如果包有任何这样的方法,这将阻止他们正在使用。
注意----------Note----------
library and require can only load an installed package, and this is detected by having a "DESCRIPTION" file containing a Built: field.
library和require只能加载一个安装包,这是一个DESCRIPTION文件,其中包含一个Built:场检测。
Under Unix-alikes, the code checks that the package was installed under a similar operating system as given by R.version$platform (the canonical name of the platform under which R was compiled), provided it contains compiled code. Packages which do not contain compiled code can be shared between Unix-alikes, but not to other OSes because of potential problems with line endings and OS-specific help files. If sub-architectures are used, the OS similarity is not checked since the OS used to build may differ (e.g. i386-pc-linux-gnu code can be built on an x86_64-unknown-linux-gnu OS).
相似者在Unix下,代码检查,包下一个类似的操作系统安装R.version$platform(其中R编译平台的规范名称),它包含编译代码。包不包含编译后的代码可以共享的Unix相似者之间,而不是因为其他操作系统的行结束符和特定于操作系统的帮助文件的潜在问题。如果使用子架构,操作系统的相似性没有被选中,因为用于构建OS可能会有所不同(如i386-pc-linux-gnux86_64-unknown-linux-gnu操作系统代码可以建)。
The package name given to library and require must match the name given in the package's "DESCRIPTION" file exactly, even on case-insensitive file systems such as are common on MS Windows and Mac OS X.
包的名称library和require必须在给定的名称相匹配的包的DESCRIPTION文件完全相同,甚至是区分大小写的文件系统,如常见的MS Windows上和Mac OS X
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole.
参见----------See Also----------
.libPaths, .packages.
.libPaths,.packages。
attach, detach, search, objects, autoload, library.dynam, data, install.packages and installed.packages; INSTALL, REMOVE.
attach,detach,search,objects,autoload,library.dynam,data,install.packages和installed.packages;INSTALL,REMOVE。
The initial set of packages attached is set by options(defaultPackages=): see also Startup.
options(defaultPackages=):又见Startup设置初始设置的附加软件包。
举例----------Examples----------
library() # list all available packages[列出所有可用的软件包]
library(lib.loc = .Library) # list all packages in the default library[默认库中列出的所有软件包]
library(help = splines) # documentation on package 'splines'[文件包样条“]
library(splines) # load package 'splines'[加载包样条线“]
require(splines) # the same[同一]
search() # "splines", too[“样条线”,也]
detach("package:splines")
# if the package name is in a character vector, use[如果包的名称是一个特征向量,使用]
pkg <- "splines"
library(pkg, character.only = TRUE)
detach(pos = match(paste("package", pkg, sep=":"), search()))
require(pkg, character.only = TRUE)
detach(pos = match(paste("package", pkg, sep=":"), search()))
require(nonexistent) # FALSE[假]
## Not run: [#无法运行:]
## if you want to mask as little as possible, use[#如果你想掩盖尽可能少,使用]
library(mypkg, pos = "package:base")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|