title: Removing workspace objects whose name start by a pattern using R
body: <p>I often create temporary objects whose names start by 'tp_' and use user-defined function. In order to keep a clean workspace, I would like to create a function that removes temporary files while keeping user-defined functions.</p>
  
  <p>So far, my code is:</p>
  
  <pre><code>rm(list = setdiff(ls(), lsf.str())) # Removes all objects except functions
  rm(list = ls(, pattern = "tp_")) # Removes all objects whose name contain 'tp_'
  </code></pre>
  
  <p>I want to:</p>
  
  <ol>
  <li>Improve the second function so that is removes objects whose name <strong>start</strong> by 'tp_' (so far, it removes objects whose name <strong>contains</strong> 'tp_'). I've tried <code>substr(ls(), 1, 3)</code> but somehow cannot integrate it to my function.</li>
  <li>Combine these two functions into one.</li>
  </ol>
  
  <p>Some R objects:</p>
  
  <pre><code>tp_A = 1
  myfun = function(x){sum(x)}
  atp_b = 3
  </code></pre>
  
  <p>The function should remove only <code>tp_A</code> from the workspace.</p>