R: Removing object from parent environment using rm()

Posted by user151410 on Stack Overflow See other posts from Stack Overflow or by user151410
Published on 2010-03-21T02:28:39Z Indexed on 2010/03/21 2:31 UTC
Read the original article Hit count: 394

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about r

    Related posts about remove