[R] Please help me to understand environments

Ajay Shah ajayshah at mayin.org
Sun Mar 15 08:14:49 CET 2009


I want to write:

zap <- function(v) {
  if (exists(v)) {rm(v)}
}

But of course this doesn't work because the rm() acts on v which is
within zap() and doesn't affect the parent environment:

> x <- 1
> zap("x")
> x
[1] 1

How would I make this zap() function work?

-- 
Ajay Shah                                      http://www.mayin.org/ajayshah  
ajayshah at mayin.org                             http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.




More information about the R-help mailing list