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.
Your frames are right I think, it's just that rm is trying to remove a itself instead of evaluating a to get the quoted name of the variable to remove.  Use the list parameter instead:
rm(list=a,envir=sys.frame(-1))
                        The following code works for me.
myEnv = new.env()
assign('xx', 5, envir=myEnv)
get('xx', envir=myEnv)
rm('xx', envir=myEnv)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With