title: Remove a directory in R invoking linux commands
body: <p>I am writing code using R that invokes Linux commands to create a directory with multiple files which has to be deleted at the end.</p>
  
  <p>I tried using <code>file.remove(directory_name)</code> which removed the directory only when its empty. If the directory has files, <code>file.remove</code> didn’t work. <code>unlink(directory_name)</code> didn't remove the directory.</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>dir.create("./dir1")  
  dir.create("./dir2")  
  ............  
  ............  
  ............  
  file.remove("./dir1")  
  unlink("./dir1, recursive = TRUE")  
  </code></pre>
  
  <p><code>file.remove()</code> threw an error:</p>
  
  <blockquote>
    <p>cannot remove file './dir1', reason 'Directory not empty'.</p>
  </blockquote>
  
  <p>while, <code>unlink()</code> didn't remove the directory.</p>
  
  <p>How do I delete a directory with files in it?</p>