Installing R 3.0.2 in Ubuntu 16.04 - r

I'm having trouble trying to install R 3.0.2 in Ubuntu 16.04. I tried adding the repositories of older versions of R but the package for R 3.0.2 cannot be found in apt-get. Has anyone tried installing an older version of R on a newer version of Ubuntu? May I know what the steps are?
I tried also specifying the version in the apt-get install command but it didn't find the right package.

I see the best option in your case is to compile R. If you have never done such a thing, follow this little script in terminal:
# install common R dependencies
sudo apt-get install gcc \
g++ \
gfortran \
bzip2 \
libbz2-dev \
xorg-dev \
liblzma-dev \
libreadline-dev \
libpcre++-dev \
libcurl-dev \
libpango1.0-dev
mkdir R_alternatives
cd R_alternatives
mkdir src
mkdir 3.0.2
cd src
wget https://cran.r-project.org/src/base/R-3/R-3.0.2.tar.gz
tar -xvf R-3.0.2.tar.gz
cd R-3.0.2
#In my opinion is better to compile in one folder (avoid uncompress tar.gz source again, if you get any errors)
mkdir BuildDir
cd BuildDir
# this step will take around 2 minutes
./../configure --with-readline=no --with-x=no --prefix=/home/'user'/R_alternatives/3.0.2
# These two will take longer!!
make
make install
# following the prefix in 'configure' your R libraries are going to be installed in /home/'user'/R_alternatives/3.0.2/lib64/R/library/
# Hence, each time you compile a new R version, it will have its own libraries (this avoid R packages versions problems)
# If you wish more than one library version for the same R version, you must create a new folder and then run
export R_LIBS=/'path_to_your_new_folder'
# If you plan to use this R version in RStudio, you have to edit ~/.bash_profile, therefore you must run:
vi ~/.bash_profile
#or, It is up to you!
gedit ~/.bash_profile
#Then you put this line in end of the file
PATH=/home/'user'/R_alternatives/3.0.2/bin:$PATH
export PATH
# OR...
RSTUDIO_WHICH_R=/home/'user'/R_alternatives/3.0.2/bin/R
export RSTUDIO_WHICH_R
#PS: You can also set the R_LIBS here, in the same way!

First off, see here for a similar & older question on SO.
Pre-compiled binaries of older R releases for various Ubuntu versions (mostly the LTS releases) are available as deb's from the following website:
https://cran.r-project.org/bin/linux/ubuntu/
Unfortunately, there doesn't seem to exist a R 3.0.2 deb package for xenial; only precise still has the R 3.0.2 package. You could try to install the precise package in xenial, but that may come with its own problem set.
Might be best to compile from source following Facottons advice.

Related

How to get linux to recognize where R is located

I am sure this is a trivial question, but I am trying to install multiple R versions in Linux. I am not using R studio server pro and am instead using the free R studio server. I followed this documentation to install R but got errors when I attempted to locate it. However, when I run a command to see what version of R is installed, there is no error.
R is installed!
(base) noah#noah-VirtualBox:/opt/R/4.1.3$ /opt/R/4.1.3/bin/R --version
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
Attempts
(base) noah#noah-VirtualBox:/opt/R/4.1.3$ R
Command 'R' not found, but can be installed with:
sudo apt install r-base-core
(base) noah#noah-VirtualBox:/opt/R/4.1.3$ which R
(base) noah#noah-VirtualBox:/opt/R/4.1.3$
Steps to reproduce
export R_VERSION=4.1.3
curl -O https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz
tar -xzvf R-${R_VERSION}.tar.gz
cd R-${R_VERSION}
# Build and install R
./configure \
--prefix=/opt/R/${R_VERSION} \
--enable-memory-profiling \
--enable-R-shlib \
--with-blas \
--with-lapack
make
sudo make install
# Verify R installation
/opt/R/${R_VERSION}/bin/R --version
# Create a symlink to R
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
# Export path so Rstudio can find it
export RSTUDIO_WHICH_R='/opt/R/4.1.3/bin'
You are overcomplicating it. Just install in, say,
/opt/R/4.2.0/
/opt/R/4.1.2/
/opt/R/4.0.5/
and then either set the $PATH to the bin/ directory in the version you want, or call R directly. It is what pretty much exactly what many of us have done with two versions of R (i.e. R-release and R-devel):
$ R --version | head -1
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
$
$ /usr/lib/R/bin/R --version | head -1
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
$
$ /usr/local/lib/R-devel/bin/R --version | head -1
R Under development (unstable) (2022-05-24 r82398) -- "Unsuffered Consequences"
$
The first two are the same as that is my 'default' version. The third is my one alternate. And that is all there is to it.
If you add /usr/local/bin to your $PATH variable you would have been able to launch R, if it was not already present.
You could add it to .bashrc in your home directory
echo "export path=\"${PATH}:/usr/local/bin\"" |tee -a ~/.bashrc
Links for installing R from package, Ubuntu / Debian, RHEL 9, RHEL 8, RHEL/CentOS7
https://docs.posit.co/resources/install-r/
Also see
(Optional) Install multiple versions of R, on the same page.

How to install R from tar gz file

I have R in 3.6.3 version and I want to download 4.0.0 version. I downloaded from https://cran.r-project.org/src/base/R-4/ tar gz file but I have no idea how can I install it. Could you please give me a command which can install this R version from tar gz file ?
Install R from Source on Linux
You can find a detailed description for a range of different Linux systems here.
In short, you will need to run the following chain of commands:
First to install dependencies. This will depend on your Linux distribution. For Linux Mint, you can do
sudo apt-get build-dep r-base
Then, specify your desired R version
export R_VERSION=4.2.1
In a folder of your choice, download the .tar.gz (For versions other than 4.X, you may need to adjust the link)
curl -O https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz
tar -xzvf R-${R_VERSION}.tar.gz
cd R-${R_VERSION}
To build and install, run from the same shell
./configure \
--prefix=/opt/R/${R_VERSION} \
--enable-memory-profiling \
--enable-R-shlib \
--with-blas \
--with-lapack
make
sudo make install
In case the ./configure ... step does not work out, you may need to install the missing binaries individually by hand.
You can check the installation by running
/opt/R/${R_VERSION}/bin/R --version
and create a symlink
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
Done!
Your R installation will be in
/opt/R/${R_VERSION}

MXNet R package on an Amazon Linux Deep Learning EC2 instance

I'm attempting to setup an Amazon Linux EC2 instance with MXNet and R (and the MXNet r package available as well). Unfortunately this has been a lot harder than I expected.
I've attempted to follow the instructions from MXNet using Amazon's deep learning AMI with CUDA 8.0 on a p2.xlarge (https://mxnet.incubator.apache.org/get_started/install.html)
However I get the same error when attempting to compile the mxnet r package from this SO post:
Issues installing mxnet GPU R package for Amazon deep learning AMI
The solution discussed in that post are somewhat beyond my abilities to fully test/debug. i.e. I'm not particularly familiar with linux environment variables and such to modify. I've also reviewed some issues raised on the apache-incubator github for MXnet and those were pretty unhelpful as well.
So my questions are,
Is anyone aware of any available AMI's which come pre-packaged with R and MXNet? The ones I see seem to only include python.
Have a working set of instructions (or a script) to run on an Amazon Linux EC2 instance to install the required dependencies (assuming Im using some type of deep learning AMI that comes with CUDA 8.0 at least) to install the MXnet R package?
Right so I was the guy on the other post and I DID eventually get it working. Took 50+ hours and I'm not 100% sure where the issue was because...linux.
sudo yum install R
sudo yum install libxml2-devel
sudo yum install cairo-devel
sudo yum install giflib-devel
sudo yum install libXt-devel
sudo R
install.packages("devtools")
library(devtools)
install_github("igraph/rigraph")
install.packages(c(“DiagrammeR”, “roxygen2”, “rgexf”, “influenceR”, “Cairo”, “imager”))
cd
cd /src/mxnet
cp make/config.mk .
echo "USE_BLAS=openblas" >>config.mk
echo "ADD_CFLAGS += -I/usr/include/openblas" >>config.mk
echo "ADD_LDFLAGS += /usr/local/lib" >>config.mk
echo "USE_CUDA=1" >>config.mk
echo "USE_CUDA_PATH=/usr/local/cuda-9.0/lib64" >>config.mk
echo "USE_CUDNN=1" >>config.mk
*add another LD flag for /usr/local/lib
cd /etc/ld.so.conf.d/
sudo nano cuda.conf
Insert  /usr/local/cuda-9.0/lib64
cd
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
sudo ldconfig
cd R-package
Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"
Rscript -e "library(devtools); library(methods);options(repos=c(CRAN='https://cran.rstudio.com'));install_deps(dependencies = TRUE)"
cd ..
sudo make rpkg
THEN you gotta make sure R/Rstudio can actually find those libraries:
cd /etc/rstudio
sudo nano rserver.conf
You can add elements to the default LD_LIBRARY_PATH for R sessions (as determined by the R ldpaths script) by adding an rsession-ld-library-path entry to the server config file. This might be useful for ensuring that packages can locate external library dependencies that aren't installed in the system standard library paths. For example:
rsession-ld-library-path=/opt/local/lib:/usr/local/cuda/lib64

Sed directory not found when running R with -e flag

When I try to run the following command:
R --slave --no-save --no-restore -e "print('foo')"
I get:
/usr/local/bin/R: line 193: /usr/local/Library/ENV/4.3/sed: No such file or directory
ERROR: option '-e' requires a non-empty argument
Apparently brew recently moved the ENV folder to a new path (see here). I know I can easily symlink the new sed dir to fix the issue but I wanted to know if there is a better workaround / fix (and eventually if this will be fixed in the R source code).
This happens because brew has changed it's paths in this commit so if you've run brew update in the last 4 days, this is what has caused the breakage.
Credit goes to blindjesse for this answer, which is to brew reinstall -s r.
I ran into some other issues when I tried this though. I didn't have X11 installed and I had a conflict with the tcl-tk which meant that it caused some other failures when it was compiling so:
I installed XQuartz from https://www.xquartz.org
Symlinked it to my homebrew folder ln -s /opt/X11/include/X11 /usr/local/include/X11 (note that your homebrew directory may be different)
brew install homebrew/dupes/tcl-tk
brew link --overwrite --force tcl-tk; brew unlink tcl-tk
brew reinstall -s r
And then it worked for me. I think once the r bottle is upgraded this issue should disappear but for the moment this is what I had to do.
Upgraded to Sierra, tried the commands above and also the directions here: https://github.com/Homebrew/homebrew-science/issues/4338. After I also reinstalled the R kernel following the instructions here: https://github.com/IRkernel/IRkernel, things started working again. Oy vey.
To reinstall the R kernel, start R in the terminal and enter the following:
install.packages(c('repr', 'IRdisplay', 'crayon', 'pbdZMQ', 'devtools'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec() # to register the kernel in the current R installation
Rather than having sed's path hardcoded, a simple workaround is to edit the R script and to change line 193 with
SED=$(which sed)

error: with-readline=yes (default) and headers/lib are not available

I am trying to install RHadoop. I have used following instruction in a Virtual box Ubuntu 12.04 64 bit version.
$wget https://launchpad.net/ubuntu/quantal/+source/r-base/2.15.1-3ubuntu1/+files/r-base_2.15.1.orig.tar.gz
$ tar -zxvf r-base_2.15.1.orig.tar.gz
$ sudo apt-get install gfortran
$ cd R-2.15.1/
$ ./configure --with-x=no
When I run this command, I get the error mentioned above. Google also does not have any suggestions for this error although many talk about X11
Readline is a GNU package that you can find here; your first option consists in installing it before trying to build R again.
Alternatively, if you are sure you do not need R to be built with this library, you can simply set with-readline to "no":
./configure --with-x=no --with-readline=no
Setting readline to no is something I considered, but than think of this, what if you need it. I am not even sure what it is 100%, but I assume it lets R read from user input of some sort.
Anyways, I just resolved this error by installing readline-devel on centos via yum. On debian I think it's something like libreadline-dev. The point is that you need development files which include .h files necessary for R.
This solution works for me:
error: --with-x=yes (default) and X11 headers/libs are not available
Solution:
Code:
$ sudo apt-get install xorg-dev
For Centos 7, to install X11
# yum install xorg-x11-server-devel libX11-devel libXt-devel
Now ./configure

Resources