title: R Global Function to Clear Workspace and Dump Storage
body: <p>I was hoping to make a global function that would clear my workspace and dump my memory. I called my function &quot;cleaner&quot; and want it to execute the following code:</p>
  <pre><code>remove(list = ls())
  gc()
  </code></pre>
  <p>I tried making the function in the global environment but when I run it, the console just prints the text of the function. In my function file to be sourced:</p>
  <pre><code>cleaner &lt;- function(){
      remove(list = ls())
      gc()
      #I tried adding return(invisible()) to see if that helped but no luck
  }
  
  cleaner()
  </code></pre>
  <p>Even when I make the function in the script I want it to run (cutting out any potential errors with sourcing), the storage dump seems to work, but it still doesn't clear the workspace.</p>
  <p><a href="https://i.stack.imgur.com/g2TFr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g2TFr.png" alt="enter image description here" /></a></p>