You might want to look at rm to see how that function handles the problem.

--
David Winsemius

On Mar 15, 2009, at 3:14 AM, Ajay Shah wrote:

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

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to