Rscript calling different R version - r

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™.

Related

Is there a way to toggle between versions of R on linux?

I have two versions of R on my linux machine (Ubuntu 18.04). I need R 4.0.2 to run an analysis that requires library (psych); and I need R 3.6.3 to run an afni analysis (3dLME). Right now, R 4.0.2 is in usr/bin/R and R 3.6.3 is usr/local/bin. However, "which R" will only return /usr/bin/R.
I have tried to add /usr/local/bin/R to my .bashrc with no luck. Is there a way to toggle back and forth between which R version that linux will use? Optimally, I would like Rstudio to use 4.0.2, but afni to use 3.6.3; but I am also fine with editing my .bashrc file when I need to use the different tools. Thanks!
See if this tutorial helps. It states, as part of the instructions,
If you want to override which version of R is used then you can set
the RSTUDIO_WHICH_R environment variable to the R executable that you
want to run against. For example:
export RSTUDIO_WHICH_R=/usr/local/bin/R Not that in order for RStudio
to see this environment variable when launched from the Ubuntu desktop
Applications menu (as opposed to from a terminal) it must be defined
in the ~/.profile file.

How is to add R and Rtools paths in the environment variable?

I have installed R-3.5.1 and Rtools35.exe. But I am unable to install packages in R. Somewhere I got,
Make sure the R and Rtools paths are added in the environment variable.
But I don't know what is environment variable and how is to add R and Rtools paths in the environment variable?
Edit
The answer provided How to add Rtools\bin to the system path in R requires library(devtools). But install.packages("devtools") isn't working.
Installing package that has heavy dependencies just to set environment variables doesn't seem to be good solution.
Below solution is for R 4.0.0 and rtools40.
This uses powershell bash, it should be available on all recent Windows versions.
$ENV:PATH = "C:\R\bin;C:\rtools40\usr\bin;$ENV:PATH"
You can see full R 4.0.0 setup on Windows in this CI yaml.
Note that in powershell it is best to refer to applications using .exe suffix, because powershell has many aliases, so using R or curl will not do what you expect, you need R.exe or curl.exe instead.

Uninstall/Update R in El Capitan

I'm trying to update R from 3.2.2 (Fire safety) to 3.3.1 (Bug in your hair) on MacOS 10.11.15 (El Capitan).
Initially I tried to use the R-3.3.1.pkg from CRAN, which allowed me to use the new version in R.app. However when trying to access R through terminal, and through Sublime REPL, the previous version appears even though the installation should have deleted previous copies of R.
How do I fully delete the old copy? In El Capitan, the Frameworks folder is no longer present, so the previous fix:
rm -rf /Library/Frameworks/R.framework /Applications/R.app \
/usr/bin/R /usr/bin/Rscript
Does not work.
P.S. (meta) how can I fireproof myself against these OS conflicts in future? Should I just run R through a VM?
This was the problem for me.
Anaconda, the python distribution provided by continuum analytics, contains a copy of R for some reason.
Therefore, if you delete your copy of R from CRAN, that (outdated) copy of R will become the default R for use in terminal, sublimeREPL, etc.
In general, booting up R and running R.home() will reveal the installation directory.
Since I want to use R and python, and update them independently, I will stop using Anaconda.

Run R (from pkg) in terminal on OS X

I just installed MacOS version of R from the CRAN web site. Within the R GUI application, everything works fine. However, I'm unable to run it from terminal. Trying to trigger R or Rscript in terminal yields a message indicating that neither command exists.
Also I do not see corresponded scripts in /Applications/R.app/Contents/.
How can I run R from terminal?
PS: I know brew installation will help. But I want this version of R from CRAN web site.
The R installer creates /Library/Frameworks/R.framework/ directory in addition to /Applications/R.app/.
So, you need add a correct directory to the Library dir. For my packages:
R_APP_DIR=/Library/Frameworks/R.framework/Versions/3.2/Resources/
export PATH=$R_APP_DIR:$PATH

Rscript pointing to incorrect R version in local build

I recently installed a local version of R 3.1.0 on a Linux Redhat server as follows:
# from R-3.1.0 directory
./configure --prefix=$(pwd)
make
make install
In addition, I've updated PATH and R_LIBS in my .bashrc. If I run path/to/local/R/bin/Rscript --version, then it returns the proper version number. However, if I give it a test script that prints sessionInfo it yields information from the system-wide R installation.
Is there any more I need to do to run the local version of R using Rscript? From reading a similar issue here, it looks like the code above should be all that's necessary. There's a similar SO issue here, but it's unresolved.
Edit:
I just fired up Ubuntu in a VM and was able to install R locally and run Rscript without problem (using the same commands listed above). Have I gone crazy? Is there anything that might be floating around the Redhat environment on this server that might mess up the installation? Sanity checks?

Resources