title: Source function in R, error cannot find file - do I have to change working directory?
body: <p>This may be a duplicate, but I couldn't find a solution when I searched online and it's an issue that has been bugging me for some time. I am given a zip file with 2 .R files, I download the zip and move the .R files into a directory on my computer, let's say "/Users/Home/StatisticsStuff/LearningR/".</p>
  
  <p>My two files are Stats1.R and Stats2.R, and the first line of code in Stats1.R is:</p>
  
  <pre><code>source(Stats2.R)
  </code></pre>
  
  <p>and I get the following error message:</p>
  
  <pre><code>&gt; source("Stats2.R")
  Error in file(filename, "r", encoding = encoding) : cannot open the connection
  In addition: Warning message:
  In file(filename, "r", encoding = encoding) : cannot open file 'Stats2.R': No such file or directory
  </code></pre>
  
  <p>when i run getwd(), to see which working directory I'm in, I get:</p>
  
  <pre><code>getwd()
  "/Users/Home"
  </code></pre>
  
  <p>It seems like it would be a pain to have to change working directories in order to source files? Is there something I'm doing wrong here with regards to what I'm expecting from the source() function? Do I have to put a line in my code above everything else using setwd("whatever the correct wd is").</p>
  
  <p>Any thoughts appreciated!</p>