title: R: source() and path to source files
body: <p>There must be something that I don't understand about the <code>source()</code> command in R. I'm still new to it, but I cannot for the life of me understand how it gets its directories from! My problem is this:</p>
  
  <p>I have a wrapper script, <code>wrapper.R</code>, and a source file containing some functions, <code>functions.R</code>. Both of these are in the same directory. If I call <code>source('functions.R')</code> inside the wrapper script, while standing inside the directory where both files are located, everything is fine. However, I want to be able to run my <code>wrapper.R</code> script from some <em>other</em> directory, <em>i.e.</em> not the one where these script are located. If I run my wrapper for another directory, it doesn't work, and I get a <code>cannot open the file</code> error.</p>
  
  <p>I googled and found lots of different threads, but <a href="https://stackoverflow.com/questions/12048436/r-sourcing-files-using-a-relative-path">this question</a> seemed to be very clear. The way I understand it, the way I'm doing it <em>should work</em>. Clearly, I'm misunderstanding something. My reading of that thread leads me to believe that <code>source()</code> works on the directory in which the file that calls <code>source()</code> is located in. My reading also leads me to believe that I should not be using <code>chdir = TRUE</code>, as I want to keep the advertised relative directory.</p>
  
  <p>Seeing as it doesn't work... what am I misunderstanding? How can I source files in the same directory as my wrapper script when called from somewhere else?</p>