title: Rscript calling different R version
body: <p>I have read <a href="https://stackoverflow.com/questions/35646882/rscript-using-incorrect-r-version">this post</a> and <a href="https://stackoverflow.com/questions/7935708/rscript-issue-using-different-version-of-r">this post</a> and <a href="https://stackoverflow.com/questions/24348382/rscript-pointing-to-incorrect-r-version-in-local-build">this post</a> but the solutions there (most notably, using the full path to Rscript) have not resolved my problem:</p>
  
  <p>I have installed the latest R on a server in my local directory (because the system wide R is out of date), and added this directory to the PATH environment variable in <code>.bashrc</code>.  From the command line I get the following:</p>
  
  <pre><code>  $ R --version
    R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
  </code></pre>
  
  <p>And</p>
  
  <pre><code>  $ Rscript --version
    R scripting front-end version 3.4.3 (2017-11-30)
  </code></pre>
  
  <p>Which is what I expect.  However, if I have the following script (named <code>test.r</code>):</p>
  
  <pre><code> #!/path/to/my/local/bin/Rscript
  
   sessionInfo()$R.version$version.string
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code> $ ./test.r
   [1] "R version 3.3.2 (2016-10-31)"
  </code></pre>
  
  <p>Which is a different version.</p>
  
  <p>(On a related note, when I use the <code>parallel</code> and <code>doParallel</code> libraries, it is apparent that the spawned processes are also using the older version of R.  I suspect the root of these issues is the same.)</p>
  
  <p>It seems to me that .bashrc is not the right place to set the PATH for this scenario.  What is the right way to do this?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This scenario arose on an HPC cluster, and I found that <code>module unload R</code> removed the older version of R from my environment.  However, even with the old R module loaded, my local version was still first in my PATH, as set by .bashrc.  So the environment in which R is getting called by Rscript (or by <code>#!/usr/bin/env Rscript</code>, for that matter) must not be looking in my .bashrc.  This is not a shock to me, but I still do not know The Right Way™ to set the PATH so the above works As Expected™.</p>