attach(what, pos = 2, name = deparse(substitute(what)), warn.conflicts = TRUE)
| what | a named list, data frame, environment, or file containing the list of objects and functions. |
| pos | an integer value representing the position of the package to be attached in the search list. |
| name |
a character string indicating the name of the environment displayed in
the search list.
|
| warn.conflicts | a logical value. If TRUE (the default), gives warning messages if the new objects conflict with the objects in the attached packages. |
x <- data.frame(Name=c("Joe","Bill"), Age=c(29,41))
attach(as.data.frame(x), name="MyData") # attach a data frame
# Now the columns are available:
Name
# [1] Joe Bill
# Levels: Bill Joe
exists("Age")
# TRUE
search()
tmpsave <- tempfile("save")
save(list=names(x), file=tmpsave)
detach(2)
# Now the columns are no longer available:
exists("Age")
# FALSE
attach(tmpsave)
Age
# [1] 29 41
detach(2)
unlink(tmpsave) # clean up