foo <- function(object) {
cat("Local objects in foo():
")
print(ls())
attachLocally(object)
cat("Local objects in foo():
")
print(ls())
for (name in ls()) {
cat("Object '", name, "':
", 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)
print(a)
Run the code above in your browser using DataLab