title: Write a function to remove object if it exists
body: <p>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:</p>
  
  <pre><code>ifrm &lt;- function(arg)
  {
     if(exists(as.character(substitute(arg)))){rm(arg)}
  }
  </code></pre>
  
  <p>Unfortunately this does not remove the object if it exists</p>
  
  <pre><code>&gt; ifrm &lt;- function(arg)
  + {
  +    if(exists(as.character(substitute(arg)))){rm(arg)}
  + }
  &gt; a &lt;- 2
  &gt; ifrm(a)
  &gt; a
  [1] 2
  </code></pre>
  
  <p>Any hints what I do wrong here?</p>
  
  <p>Best Albrecht</p>