title: How to remove a directory in R?
body: <p>After some research I found out that the following works:</p>
  
  <pre><code>unlink("mydir")
  </code></pre>
  
  <p>and you have to use the <code>recursive</code> option in case you want to remove recursively:</p>
  
  <pre><code>unlink("mydir", recursive=TRUE)
  </code></pre>
  
  <p>However, I noted that <code>unlink("mydir")</code> alone, without the <code>recursive</code> option, does not produce any output when <code>mydir</code> contains subdirectories: it does not remove the dirs but does not show any warning. Just nothing:</p>
  
  <pre><code>&gt; list.dirs()
  [1] "."          "./r"
  &gt; dir.create("test")
  &gt; dir.create("test/test2")
  &gt; list.dirs()
  [1] "."            "./r"   "./test"       "./test/test2"
  &gt; unlink("test")          ######### here I would expect a warning #########
  &gt; list.dirs()
  [1] "."            "./r"   "./test"       "./test/test2"
  &gt; unlink("test", recursive=TRUE)
  &gt; list.dirs()
  [1] "."          "./r"
  </code></pre>
  
  <p>Is there any way to get any kind of "notification", like the one you would get in UNIX systems?</p>
  
  <pre><code>$ rmdir test
  rmdir: failed to remove «test»: Directory not empty
  </code></pre>
  
  <p>I am using R version 3.1.2 (2014-10-31). I tried playing with <code>options(warn=1)</code> etc but no luck.</p>