test <- function(){
a = 3
b = c(1,2,3)
c = matrix(-99, 3, 4)
print(getObjects())
}
getObjects <- function(){
return(ls(envir=parent.frame(n = 1)))
}
test()
#[1] "a" "b" "c"
Of course you could simply use the defaults for ls
:
test <- function(){
a = 3
b = c(1,2,3)
c = matrix(-99, 3, 4)
ls()
}
From the documentation:
name: which environment to use in listing the available objects. Defaults to the current environment.