attachLocally.list.RdAssigns an objects elements locally.
# S3 method for list
attachLocally(object, fields=NULL, excludeFields=NULL, overwrite=TRUE,
envir=parent.frame(), ...)An object with named elements such as an environment,
a list, or a data.frame.
A character vector specifying elements to be copied.
If NULL, all elements are considered.
A character vector specifying elements not to
be copied. This has higher priority than fields.
If FALSE, fields that already exists will not be
copied.
The environment where elements are copied to.
Not used.
attachLocally() of class Object.
attach().
foo <- function(object) {
cat("Local objects in foo():\n")
print(ls())
attachLocally(object)
cat("\nLocal objects in foo():\n")
print(ls())
for (name in ls()) {
cat("\nObject '", name, "':\n", sep="")
print(get(name, inherits=FALSE))
}
}
a <- "A string"
l <- list(a=1:10, msg="Hello world", df=data.frame(a=NA, b=2))
foo(l)
#> Local objects in foo():
#> [1] "object"
#>
#> Local objects in foo():
#> [1] "a" "df" "msg" "object"
#>
#> Object 'a':
#> [1] 1 2 3 4 5 6 7 8 9 10
#>
#> Object 'df':
#> a b
#> 1 NA 2
#>
#> Object 'msg':
#> [1] "Hello world"
#>
#> Object 'object':
#> $a
#> [1] 1 2 3 4 5 6 7 8 9 10
#>
#> $msg
#> [1] "Hello world"
#>
#> $df
#> a b
#> 1 NA 2
#>
print(a)
#> [1] "A string"