R: Removing object from parent environment using rm()
- by user151410
Hi,
I am trying to remove an object from the parent environment.
rm_obj <- function(obj){
a <-deparse(substitute(obj))
print (a)
print(ls(envir=sys.frame(-1)))
rm(a,envir=sys.frame(-1))
}
> x<-c(1,2,3)
> rm_obj(x)
[1] "x"
[1] "rm_obj" "x"
Warning message:
In rm(a, envir = sys.frame(-1)) : object 'a' not found
This will help clarify my misunderstanding regarding frames.
Thanks in advance,
Russ