I have read this post and this post and this post but the solutions there (most notably, using the full path to Rscript) have not resolved my problem:
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 .bashrc
. From the command line I get the following:
$ R --version
R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
And
$ Rscript --version
R scripting front-end version 3.4.3 (2017-11-30)
Which is what I expect. However, if I have the following script (named test.r
):
#!/path/to/my/local/bin/Rscript
sessionInfo()$R.version$version.string
I get this:
$ ./test.r
[1] "R version 3.3.2 (2016-10-31)"
Which is a different version.
(On a related note, when I use the parallel
and doParallel
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.)
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?
Thanks in advance!
EDIT
This scenario arose on an HPC cluster, and I found that module unload R
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 #!/usr/bin/env Rscript
, 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™.