I am trying to write a function that removes an object if it exists. The reason is that I want to get rid of the log-message Error: object 'arg' not found. I tried the following:
ifrm <- function(arg)
{
if(exists(as.character(substitute(arg)))){rm(arg)}
}
Unfortunately this does not remove the object if it exists
> ifrm <- function(arg)
+ {
+ if(exists(as.character(substitute(arg)))){rm(arg)}
+ }
> a <- 2
> ifrm(a)
> a
[1] 2
Any hints what I do wrong here?
Best Albrecht