Skip to content

Please help me to understand environments

2 messages · Ajay Shah, David Winsemius

#
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:
[1] 1

How would I make this zap() function work?
#
You might want to look at rm to see how that function handles the  
problem.