Running different versions of R in the RStudio IDE is, on occasion, required to load older packages.

[This article was first published on R-posts.com, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This is a re-post by the author from:
https://www.bsetmet.com/index.php/2019/05/26/gist-rstudio-vsersions-ubuntu/

I got fed up with the manual process, so I started to automate the entire process Ubuntu in a bash script. This script should work for most Debian based distros.

TLDR -> Get to the Code on Github!

(Through out this process stackoverflow was my friend.)

Generally the process for 3.4.4 (for example) is to:

1. Download R from CRAN

https://cran.r-project.org/src/base/R-3/R-3.4.4.tar.gz

2. Un-archive files

tar -xzvf R-3.4.4.tar.gz

3. Make from source

(from inside the un-archived directory)
sudo ./configure --prefix=/opt/R/$r_ver --enable-R-shlib && \
sudo make && \
sudo make install

4. Update environment variable  for R-Studio

export RSTUDIO_WHICH_R="/opt/R/3.4.4/bin/R"

5. Launch R-Studio (in the context of this environment variable)

rstudio

I started down the road of manually downloading all the .tar.gz files of the versions that I might want to install, so then I grabbed a method for un-archiving all these files at one time.

find . -name '*.tar.gz' -execdir tar -xzvf '{}' \;

Here is where I started to Build and install R from source in an automating script at once I use this

[
[code]]czoyOTQ6XCIjIS9iaW4vYmFzaA0KIyBydW4gd2l0aCBzdWRvDQpmdW5jdGlvbiBjb25maWdfbWFrZV9pbnN0YWxsX3IoKXsNCiAgZm97WyYqJl19bGRlcl9wYXRoPSQxDQogIHJfdmVyc2lvbj0kMg0KICBjZCAkZm9sZGVyX3BhdGgNCiAgc3VkbyAuL2NvbmZpZ3VyZSAtLXByZWZpeHtbJiomXX09L29wdC9SLyRyX3ZlcnNpb24gLS1lbmFibGUtUi1zaGxpYiAmYW1wOyZhbXA7IFxcXFwNCiAgc3VkbyBtYWtlICZhbXA7JmFtcDsgXFxcXHtbJiomXX0NCiAgc3VkbyBtYWtlIGluc3RhbGwNCn0NCmNvbmZpZ19tYWtlX2luc3RhbGxfciB+L0Rvd25sb2Fkcy9SLTMuNC40IDMuNC40XCI7e1smKiZdfQ==[
]

From here i added a menu system i found on stack overflow. This script prompts to install whatever version of R you are attempting to launch if not yet installed.

https://gist.github.com/seakintruth/95d49b6ea316c2b8a6e283e1ee1a3f3a

This file can be downloaded, inspected and run from the github RAW link, of course to run a .sh file it needs to be updated to be executable with

[
[code]]czo0MTpcInN1ZG8gY2htb2QgK3ggUlNUVURJT19WZXJzaW9uX0xhdW5jaGVyLnNoXCI7e1smKiZdfQ==[
]

I have found that by just directing the gist’s contents directly into bash i can skip that step!

[
[code]]czoxMDI6XCJiYXNoICZsdDsoY3VybCAtcyBodHRwczovL2dpc3QuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3NlYWtpbnRydXRoLzk1ZDR7WyYqJl19OWI2ZWEzMTZjMmI4YTZlMjgzZTFlZTFhM2YzYS9yYXcpXCI7e1smKiZdfQ==[
]

Executing this script also places a copy of it’s self in the current users local profile, and a link to a new .desktop for the local Unity Launcher on first run. This allows me to run this custom launcher from the application launcher. I then pin it as a favorite to the Dock manually.

The completed can be found on Github HERE or view RAW script from Github

Jeremy D. Gerdes
[email protected]
April 2019
Creative Commons by-sa 4.0 
(CC BY-SA 3.0) https://creativecommons.org/licenses/by-sa/3.0/ 

To leave a comment for the author, please follow the link and comment on their blog: R-posts.com.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)