title: Copying files over network MUCH slower with `file.copy` than `system(mv ...)`
body: <p>I have been having some issues with R becoming very sluggish when accessing files over our corp network. So I dropped back and did some testing and I was shocked to discover that the R <code>file.copy()</code> command is <strong><em>MUCH</em></strong> slower than the equivalent file copy using <code>system(mv ...)</code>. Is this a known issue or am I doing something wrong here?</p>
  
  <p>Here's my test:</p>
  
  <p>I have 3 files:</p>
  
  <ul>
  <li><code>large_random.txt</code>  - ~100MB </li>
  <li><code>medium_random.txt</code> - ~10MB </li>
  <li><code>small_random.txt</code>  - ~1 MB</li>
  </ul>
  
  <p>I created these on my Mac like so:</p>
  
  <pre><code>dd if=/dev/urandom of=small_random.txt bs=1048576 count=1
  dd if=/dev/urandom of=medium_random.txt bs=1048576 count=10
  dd if=/dev/urandom of=large_random.txt bs=1048576 count=100
  </code></pre>
  
  <p>But the following R tests were all done using Windows running in a virtual machine. The J drive is local and the N drive is 700 miles away. </p>
  
  <pre><code>library(tictoc)
  
  test_copy &lt;- function(source, des){
    tic('r file.copy')
    file.remove(des)
    file.copy(source, des )
    toc()
  
    tic('system call')
    system(paste('rm', des, sep=' '))
    system(paste('cp', source, des, sep=' '))
    toc()
  }
  
  source &lt;- 'J:\\tidy_examples\\dummyfiles\\small_random.txt'
  des &lt;- 'N:\\JAL\\2018\\_temp\\small_random.txt'
  test_copy(source, des)
  
  source &lt;- 'J:\\tidy_examples\\dummyfiles\\medium_random.txt'
  des &lt;- 'N:\\JAL\\2018\\_temp\\medium_random.txt'
  test_copy(source, des)
  
  source &lt;- 'J:\\tidy_examples\\dummyfiles\\large_random.txt'
  des &lt;- 'N:\\JAL\\2018\\_temp\\large_random.txt'
  test_copy(source, des)
  </code></pre>
  
  <p>Which results in the following:</p>
  
  <pre><code>&gt; source &lt;- 'J:\\tidy_examples\\dummyfiles\\small_random.txt'
  &gt; des &lt;- 'N:\\JAL\\2018\\_temp\\small_random.txt'
  &gt; test_copy(source, des)
  r file.copy: 6.49 sec elapsed
  system call: 2.12 sec elapsed
  &gt; 
  &gt; source &lt;- 'J:\\tidy_examples\\dummyfiles\\medium_random.txt'
  &gt; des &lt;- 'N:\\JAL\\2018\\_temp\\medium_random.txt'
  &gt; test_copy(source, des)
  r file.copy: 56.86 sec elapsed
  system call: 4.65 sec elapsed
  &gt; 
  &gt; source &lt;- 'J:\\tidy_examples\\dummyfiles\\large_random.txt'
  &gt; des &lt;- 'N:\\JAL\\2018\\_temp\\large_random.txt'
  &gt; test_copy(source, des)
  r file.copy: 562.94 sec elapsed
  system call: 31.01 sec elapsed
  &gt; 
  </code></pre>
  
  <p>So what's going on that makes the system call so much faster? At the large file size it's > 18x slower! </p>