找回密码
 注册
查看: 7092|回复: 0

R语言:attach()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-17 09:44:19 | 显示全部楼层 |阅读模式
attach(base)
attach()所属R语言包:base

                                        Attach Set of R Objects to Search Path
                                         附加的R对象设置搜索路径

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

The database is attached to the R search path.  This means that the database is searched by R when evaluating a variable, so objects in the database can be accessed by simply giving their names.
数据库连接到R的搜索路径。这意味着该数据库是由R搜查进行评估时,一个变量,因此,数据库中的对象可以通过简单地给他们的名字来访问。


用法----------Usage----------


attach(what, pos = 2, name = deparse(substitute(what)),
       warn.conflicts = TRUE)



参数----------Arguments----------

参数:what
"database".  This can be a data.frame or a list or a R data file created with save or NULL or an environment.  See also "Details".
“数据库”。这可以是一个data.frame或list或save或NULL或环境创建一个R的数据文件。另见“详细资料”。


参数:pos
integer specifying position in search() where to attach.
search()哪里附加的整数,指定位置。


参数:name
name to use for the attached database.
要使用的名称为附加的数据库。


参数:warn.conflicts
logical.  If TRUE, warnings are printed about conflicts from attaching the database, unless that database 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。冲突是一个函数,屏蔽功能,或无功能,掩盖了非功能。


Details

详情----------Details----------

When evaluating a variable or function name R searches for that name in the databases listed by search.  The first name of the appropriate type is used.
当评估一个变量或函数名是在search中列出的数据库名称为R搜索。使用适当类型的名字。

By attaching a data frame (or list) to the search path it is possible to refer to the variables in the data frame by their names alone, rather than as components of the data frame (e.g. in the example below, height rather than women$height).
通过附加一个数据框(或列表)的搜索路径,它是指在数据框的变量,他们的名字本身,而不是作为组件的数据框(如下面的例子中,height而不是women$height)。

By default the database is attached in position 2 in the search path, immediately after the user's workspace and before all previously attached packages and previously attached databases.  This can be altered to attach later in the search path with the pos option, but you cannot attach at pos = 1.
默认情况下,数据库连接,在搜索路径中的第2位置后,立即用户的工作区之前,所有先前连接的包和以前附加的数据库。这可以改变附加在搜索路径后pos选项,但你不能附加在pos = 1。

The database is not actually attached.  Rather, a new environment is created on the search path and the elements of a list (including columns of a data frame) or objects in a save file or an environment are copied into the new environment.  If you use <<- or assign to assign to an attached database, you only alter the attached copy, not the original object. (Normal assignment will place a modified version in the user's workspace: see the examples.)  For this reason attach can lead to confusion.
数据库实际上并不重视。搜索路径上,而是创建一个新的环境和一个列表(包括一个数据框的列)或保存文件或环境中的对象的元素复制到新的环境。如果你使用<<-或assign分配到一个附加的数据库,你只改变附加的副本,而不是原来的对象。 (正常的分配将放置在用户的工作空间修改后的版本:看到的例子。)出于这个原因attach会导致混乱。

One useful "trick" is to use what = NULL (or equivalently a length-zero list) to create a new environment on the search path into which objects can be assigned by assign or load or sys.source.
一个有用的绝招使用what = NULL(或等价的一个长度为零的列表)assign或load分配到其中的对象可以搜索路径上创建一个新的环境或sys.source。

Names starting "package:" are reserved for library and should not be used by end users.  The name for an attached file is always of the form file:<VAR>what</VAR>, even if name is supplied.  Otherwise the name argument given for the attached environment will be used by search and can be used as the argument to as.environment.
"package:"保留library“不应由最终用户使用的名称开始。附加文件的名称是始终的形式file:<VAR>what</VAR>,即使name提供。 name所附的环境参数,否则将使用search可用于作为as.environment参数。

There are hooks to attach user-defined table objects of class "UserDefinedDatabase", supported by the Omegahat package RObjectTables.  See http://www.omegahat.org/RObjectTables/.
有钩子类的附加用户定义表对象"UserDefinedDatabase"的Omegahat包RObjectTables支持。看到http://www.omegahat.org/RObjectTables/。


值----------Value----------

The environment is returned invisibly with a "name" attribute.
environment"name"属性返回无形。


参考文献----------References----------

The New S Language. Wadsworth &amp; Brooks/Cole.

参见----------See Also----------

library, detach, search, objects, environment, with.
library,detach,search,objects,environment,with。


举例----------Examples----------


require(utils)

summary(women$height)   # refers to variable 'height' in the data frame[是指以数据框中的变量的“高度”]
attach(women)
summary(height)         # The same variable now available by name[现在所提供的名称相同的变量]
height &lt;- height*2.54   # Don't do this. It creates a new variable[不这样做。它创建了一个新的变量]
                        # in the user's workspace[在用户的工作空间]
find("height")
summary(height)         # The new variable in the workspace[在工作区中的新变量]
rm(height)
summary(height)         # The original variable.[原来的变量。]
height &lt;&lt;- height*25.4  # Change the copy in the attached environment[在连接环境的改变副本]
find("height")
summary(height)         # The changed copy[更改后的副本]
detach("women")
summary(women$height)   # unchanged[不变]

## Not run: ## create an environment on the search path and populate it[#无法运行:#创建一个环境上的搜索路径并填充它]
sys.source("myfuns.R", envir=attach(NULL, name="myfuns"))


转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 06:22 , Processed in 0.020684 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表