Difficulty Running Multiple Versions of R from Command Line - r

I'm in a team that is running multiple cronjobs that call R scripts from a remote machine (macos). My colleague needs to run 3.6 for a new script, while a package that is essential to mine has not been updated for it yet. I'm trying to put multiple installations on the same computer so we just specify which "R" version to call in the cronjob.
I know installing from source isn't recommended on macos, so I've been trying to follow the directions here https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Multiple-versions and ran the pkgutil --forget commands to prevent the R 3.6 installation from overwriting the R.framework/Versions/3.5 directory.
Here are the pkgutil commands that I ran:
sudo pkgutil --forget org.r-project.x86_64.tcltk.x11
sudo pkgutil --forget org.r-project.R.el-capitan.GUI.pkg
sudo pkgutil --forget org.r-project.R.el-capitan.fw.pkg
sudo pkgutil --forget org.r-project.x86_64.texinfo
Yet after installing 3.6 from CRAN, when I run the following line:
Library/Frameworks/R.framework/Versions/3.5/Resources/bin/R
Instead of the 3.5.3 console running in the terminal, the 3.6 console pops up.
I'm confused with what to do here - I've also used
ls -la 3.5/Resources/bin | grep "/->"
to check and see if a symlink was created during the install that would change the version/location but get no results, and when I run Rscript --version in the same directory as the R path shown above, I get the following output:
R scripting front-end version 3.5.3 (2019-03-11)
Though when I try to run my script using this location of Rscript I get the same error that I did when running it using R 3.6. However, once I reinstalled R 3.5.3 the script ran fine.
Basically, I think somehow the most recently installed version of R seems to override and run no matter what I do to try and insure that an older version runs instead. Can someone help me piece together how or why this is happening, or provide a suggestion as to how to install R 3.6 as the default "R" while still allowing me to run 3.5.3 for certain scripts as needed?

I have similar problem. What you observed is clearly mentioned on https://cran.rstudio.org/doc/manuals/R-admin.html#Uninstalling-under-macOS: "However, R.APP will always run the ‘current’ version, that is the last installed version.". So far, I don't know how to solve the problem either. Using Rswitch worked very well to switch R versions manually, but i don't know how to integrate Rswitch to command lines.

Related

Sometimes commands do not terminate after upgrading to R 4.0 and Ubuntu 20.04

I have upgraded R (from 3.6 to 4.0) and RStudio (from 1.1 to 1.2.5) a few days ago, and Ubuntu from 18.04 to 20.04 yesterday.
Since then, R sometimes never terminates when executing certain commands: ivreg (from package AER), summary (of a logit regression) and logitmfx (from package mfx). Sometimes these commands run fine, but most of the time I have to kill the process (killall rstudio) because R won't terminate the execution, even when pressing the red Stop button in RStudio.
When I tried example('AER'), it worked fine. Then I re-installed the package AER. It threw 10 warnings of type In readLines(file, skipNul = TRUE) : cannot open compressed file '/usr/lib/R/site-library/[package]/DESCRIPTION', probable reason 'No such file or directory' where [package] is abind, colorspace, dichromat... (but not AER).
Since then example('AER') throws a warning: no help found for ‘AER’.
I've removed and reinstalled R 4.0: it didn't help. Besides, the apt purge r-base* r-recommended r-cran-* threw a warning: dpkg: warning: while removing r-base-core, directory '/usr/lib/R/site-library' not empty so not removed. Also, there was a bunch of Package [package] is not installed, so not removed, including for [package] equal to r-cran-abind and the other listed above (this purge also returned a bunch of Note, selecting [package] for glob 'r-cran-*').
I haven't tried using R without RStudio. I was probably working on RStudio during the upgrade to Ubuntu 20.04. Also, I can't recall if this issue started after I upgraded R and RStudio (which would be my best guess) or after I upgraded Ubuntu (a day or two later).
I hope someone can help.
The solution was provided via r-sig-debian mailing list by Dirk Eddelbuettel and Sébastien Villemot.
I don't know if this is necessary, but I first did:
sudo update-alternatives --config libblas.so.3-x86_64-linux-gnu
and select /usr/lib/x86_64-linux-gnu/blas/libblas.so.3 (instead of pthread).
Then (this worked):
sudo apt install libopenblas-openmp-dev
sudo apt remove libopenblas-pthread-dev libopenblas0-pthread

R Notebook Creation Failed

When I go File-New File-R Notebook, it tells me to install some packages, but then it fails giving me this message:
Notebook Creation Failed:
"One of more packages required for R Notebook creation were not installed"
I'm trying to install those packages manually, but the package installation window disappears so quickly that I can't even see which ones I should install.
I googled it around, but couldn't fine any resource.
Can anyone help me with this?
Maybe at least provide a list of packages required to run R Notebook?
R notebooks are actually not created with a package named either RNotebook or notebook or anything similar but rather with the rmarkdown package, and it needs to be a current version. So the command would be:
install.packages("rmarkdown", dependencies=TRUE) # needs to be >= version 1.3
Then your pulldown menu selections should succeed in a current version of RStudio. .... at least that is if you have the system requirements listed in the CRAN webpage:
SystemRequirements: pandoc (>= 1.12.3) - http://pandoc.org
This worked for me:
Install latest version of R from cran website
Start RStudio pointing to this version of R.
On Mac set env variable as show below and start RStudio from terminal
Then "Install Package" in RStudio for "markdown" and other ppackages will work properly installing latest required packages to open notebook
➜ export RSTUDIO_WHICH_R=/usr/local/bin/R
Don't press the error message, and read whatever you can from the installation popup under it. In my case the last message was that it has problems compiling "digest". I installed "digest" manually (install.packages("digest",type = "binary")). Then it all worked.
Mac, R version 3.6, Rstudio desktop 1.2.
I had exactly the same problem. By reading the error logs, I found g++ command not found. So just installed it and it worked fine next time I've tried.
I faced the same problem. I am using the latest version of R and RStudio and all of the installed packages are up-to-date.
Now, talking about the error in installation of packages. Follow the steps below and you will have R Notebook up and running:
Run the command
install.packages("rmarkdown", dependencies=TRUE)
You will observe several messages on the console during installation. Browse through them and jot the ones where there is ERROR in installation of some other dependent package. In my case, it was 'backports'. The error message will be like this:
ERROR: compilation failed for package 'backports'
It can be different in your case but the point is to note down the name of the package that is facing compilation issues. Use an editor(npp) to save the name of the package.
Once you get the name of the package, execute the following command:
install.packages("backports", type="binary")
After successful execution of the above command, go to File drop down and select R Markdown. Go with auto installation of the rmarkdown and rprojroot packages. They will be successfully installed and you can now use R Notebook
Let us know if this solution worked for you.
I just found the answer myself so I'm posting.
I guess there was something wrong with the server.
I went into tools-global options-packages and chose different CRAN mirror, then it worked.
UPDATE YOUR VERSION OF R - that was my solution, I had the same problem.
( First two commands ensure you get the MOST RECENT version of R which I found on a Digital Ocean page)
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ sudo add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/'
$ sudo apt-get update
$ sudo apt-get install r-base
WITHOUT the first two lines I ended up with R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
WITH the first two lines I got R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
After reinstalling R Studio, the Files -> RMarkdown was able to install all those subpackages and WORK. Hurray!

remove anaconda R from Ubuntu

I have been using ipython notebook to run some R scripts. Now the problem is I have two R versions on my Ubuntu 14.04.
One is R.3.2.2 at /home/MYNAME/anaconda2/bin/R, another one is the R which I need for R studio,
now the problem is I want to only use R.3.3.1 for my system as I need some advanced task to be done.
I use conda uninstall r, after running this, according to the print out, a lot of R related packages is removed, if i run conda uninstall r again, it said
Fetching package metadata .......
Using Anaconda Cloud api site https://api.anaconda.org
Solving package specifications: ..........
Error: no packages found to remove from environment: /home/MyName/anaconda2
but when I run Which R again, still it is the anaconda R, if I run R in the terminal, it is still R3.2.2, anyone knows how could I remove this anaconda R version?
You probably needed to run hash -r in your session (or rehash if using zsh) to update your executables on PATH for the which command. A new terminal session would also fix the problem.
you can try conda uninstall r-base, this will remove R and all of the R-library.
The questions also implies that one cannot use anaconda R with rstudio.
On Linux you can
export RSTUDIO_WHICH_R=/home/USER/anaconda3/bin/R
and add to .profile (d/o your distro) to use rstudio with anaconda R and packages

Installing R on Apache Zeppelin

I'm trying to install Apache Zeppelin on my old computer that runs Ubuntu. So far, I'm able to install Zeppelin very easily by cloning the latest 0.6.0 snapshot release using
git clone https://github.com/apache/incubator-zeppelin.git
cd incubator-zeppelin
mvn clean package -DskipTests
but I want to have R on Zeppelin. Supposedly, the 0.6.0 snapshot has two R interpreters, but when I run the R tutorial (the pre-made note that uses %r), I get this list of errors.
I followed several guides to try and install R as an interpreter, but each one resulted in some kind of error. I tried this instructional:
http://www.r-bloggers.com/interactive-data-science-with-r-in-apache-zeppelin-notebook/, and got a build failure on "R Interpreter". The error message was
"dependency 'evaluate' is not available for package 'rzeppelin'
* removing '/home/rebecca/Zeppelin-With-R/R/lib/rzeppelin'"
and then a bit lower down
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default) on project zeppelin-zrinterpreter: Command execution failed. Process exited with an error: 1
I also tried this Stack Overflow guide: Anyone tried to add R interpreter onto Apache Zeppelin?, and while I was able to run incubator-zeppelin, I received an error when I used either the %spark.r or %r interpreter tags, saying both "interpreter not found" and "prefix not found". Spark doesn't work either after following the first solution, getting the same error mentioned in the second solution (the jar file not being there), and then trying the second solution.
Does anyone have a guide for installing R onto the newest version of Zeppelin? I'm very flexible in the way I can install it. I can run other operating systems onto my computer, and I also have Virtual Box installed on my other computer, which is a mac.
There is currently a bug in the latest HEAD of zeppelin that was recently introduced and prevents the R interpreter from launching cleanly
Did anyone created a Zeppelin Jira Issue for that?
For me it is working on Zeppelin branch-0.6
build Zeppelin with r profile: -DskipTests -Prthis will...
create a directory 'R' in git repo root
copy the 'zeppelin-rinterpreter*.jar' into git_repo_root/interpreter/spark
build Zeppelin with build distro profile: e.g. -DskipTests -Pbuild-distr -Pspark-1.6 -Phadoop-2.6
use zeppelin-distribution/target/zeppelin*.tar.gz for installation
ensure both 1.1 and 1.2 are present in your zeppelin installation
The error you're getting is that you need to have the R package evaluate installed. You can install this simply by launching R and typing install.packages('evaluate').
That said, your excerpt mentions the directory Zeppelin-with-R. That's my repo, which is the R interpreter in the form when it was accepted into Zeppelin. That is version 0.5.6, not 0.6.0. There is currently a bug in the latest HEAD of zeppelin that was recently introduced and prevents the R interpreter from launching cleanly. Your best bet for now is to use the one from my repo and install clean, without trying to pull-in from Zeppelin HEAD.

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