title: file.copy: overcoming Windows long path/filename limitation
body: <p>I have a table in R containing many files that I need copied to a destination folder. The files are spread out over dozens of folders, each several sub-folders down. I have successfully used the following code to find all of the files and their locations:</p>
  <p><code>(fastq_files &lt;- list.files(Illumina_output, &quot;.fastq.gz&quot;, recursive = TRUE, include.dirs = TRUE) %&gt;% as_tibble)</code></p>
  <p>After appending the full path, I have a tibble that looks something like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>full_path</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Q:/IlluminaOutput/2019/091119 AB NGS/Data/Intensities/BaseCalls/19-15897-HLA-091119-AB-NGS_S14_L001_R1_001.fastq.gz</td>
  </tr>
  <tr>
  <td>Q:/IlluminaOutput/2019/091119 AB NGS/Data/Intensities/BaseCalls/19-15236-HLA-091119-AB-NGS_S14_L001_R2_001.fastq.gz</td>
  </tr>
  <tr>
  <td>Q:/IlluminaOutput/2018/062818AB NGS/Data/Intensities/BaseCalls/18-06875-HLA-062818-NGS_S11_L001_R1_001.fastq.gz</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Using the <code>file.copy</code> function gives an error that the file name is too long, a known issue in Windows (I am using RStudio on Windows 10).</p>
  <p>I found that if I set the working directory directory to the file location, I am able to copy files. Starting with a table like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>file</th>
  <th>path</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>19-14889-HLA-091119-AB-NGS_S14_L001_R1_001.fastq.gz</td>
  <td>Q:/IlluminaOutput/2019/091119 AB NGS/Data/Intensities/BaseCalls/</td>
  </tr>
  <tr>
  <td>19-14889-HLA-091119-AB-NGS_S14_L001_R2_001.fastq.gz</td>
  <td>Q:/IlluminaOutput/2019/091119 AB NGS/Data/Intensities/BaseCalls/</td>
  </tr>
  <tr>
  <td>18-09772-HLA-062818-NGS_S11_L001_R1_001.fastq.gz</td>
  <td>Q:/IlluminaOutput/2018/062818AB NGS/Data/Intensities/BaseCalls/</td>
  </tr>
  <tr>
  <td>18-09772-HLA-062818-NGS_S11_L001_R2_001.fastq.gz</td>
  <td>Q:/IlluminaOutput/2018/062818AB NGS/Data/Intensities/BaseCalls/</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I used the following code to sucsessfully copy the first file:</p>
  <pre><code>(dir &lt;- as.character(as.vector(file_and_path[1,2])))
  setwd(dir)
  (file &lt;- as.character(as.vector(file_and_path[1,1])))
  (file.copy(file, Trusight_output) %&gt;% as.tibble)
  </code></pre>
  <p>I got this to work, but I don't know how to apply these steps to every column in my table. I think i probably have to use the <code>lapply</code> function, but I'm not sure how to construct it.</p>