title: Relative paths in R: how to avoid my computer being set on fire?
body: <p>A while back I was reading an article about improving project <a href="https://www.tidyverse.org/articles/2017/12/workflow-vs-script/" rel="nofollow noreferrer">workflow</a>. The advice was not to use <code>setwd</code> or my computer would burn:</p>
  
  <blockquote>
    <p>If the first line of your R script is</p>
    
    <p>setwd("C:\Users\jenny\path\that\only\I\have") </p>
    
    <p>I will come into your office and SET YOUR COMPUTER ON FIRE .</p>
  </blockquote>
  
  <p>I started using the <code>here</code> package and it worked great until I started to schedule scripts using <code>cronR</code>. After asking <a href="https://stackoverflow.com/questions/52775824/correct-way-to-use-here-package-with-cronr-scheduling">this</a> question my laptop was again threatened with arson:</p>
  
  <blockquote>
    <p>If the first line of your #rstats script is wd &lt;- here(), I will come
    into your lab and SET YOUR COMPUTER ON FIRE.</p>
  </blockquote>
  
  <p>Fearing for my laptop's safety I started using the method suggested in the answer to get relative file paths:</p>
  
  <pre><code>wd &lt;- Sys.getenv("HOME")
  wd &lt;- file.path(wd, "projects", "my_proj") 
  </code></pre>
  
  <p>Which worked for me but not people I was working with who didn't have the same <code>projects</code> directory. So now I'm confused. What is the safest / best way get relative file paths so that a project can be portable?</p>
  
  <p>There are quite a few options: <a href="https://stackoverflow.com/questions/11977417/package-relative-paths-in-r">1</a>, <a href="https://stackoverflow.com/questions/3452086/getting-path-of-an-r-script">2</a>. My requirements are to source functions/scripts and read/write csv files. Perhaps the <code>rprojroot</code> package is the best bet?</p>