R语言base包 attach函数使用说明

返回R语言base包函数列表


功能\作用概述:

数据库附加到R搜索路径。这意味着在计算变量时,数据库是由R搜索的,因此只需给出对象的名称就可以访问数据库中的对象。


语法\用法:

attach(what, pos = 2L, name = deparse1(substitute(what), backtick=FALSE),
warn.conflicts = TRUE)


参数说明:

what : “数据库”。这可能是数据框或者使用save或NULL或环境创建的列表或R数据文件。另请参见“详细信息”。

pos : 指定search()中要附加的位置的整数。

name : 用于附加数据库的名称。以package:开头的名称是为库保留的。

warn.conflicts : 合乎逻辑。如果为TRUE,则打印有关附加数据库的冲突的警告,除非该数据库包含对象。冲突。好的. Aconflict是屏蔽函数的函数,或屏蔽非函数的非函数。


示例\实例:

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 < - 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 << - 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"))

## End(Not run)