What's the best way to install R packages on Linux? - r

I happen to have Linux Mint on my machine (and I am not very experienced in Linux). When trying to install R packages (using install.packages()) on Linux Mint, I've got the following problems:
The installation process goes very slowly (the packages are being compiled each time)
Some packages could not be installed due to compilation errors.
So, I wonder, is there any standard approach to install packages for Linux Mint?

The repositories are available in any standard Ubuntu installation via the package manager. To get the latest version try adding cran.rstudio.com repository for Ubuntu:
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
(Details see R-Project homepage)

Related

R-base could not be upgraded to 4.0: showing "r-base is already the newest version (3.4.4-1xenial0)"

I have tried to upgrade R from 3.4.4 to 4.0 in Ubuntu 16.04.7 LTS (Xenial Xerus). I have followed and run the following scripts.
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/'
$ sudo apt-get update
$ sudo apt install r-base
Output:
"Reading package lists... Done
Building dependency tree
Reading state information... Done
r-base is already the newest version (3.4.4-1xenial0)".
The terminal always showed that "r-base is already the newest version" and refused to upgrade. I tried to upgrade R 3.6 as well and got a similar issue. Any thoughts? Thank you so much for your help.

How do I solve a dependency error that prevents me from installing R 4.0 on Ubuntu 18.04?

I'm trying to install R 4.0 on Ubuntu, but get this error:
$ sudo apt-get install r-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
r-base : Depends: r-base-core (>= 4.0.0-1.2004.0) but it is not going to be installed
Depends: r-recommended (= 4.0.0-1.2004.0) but it is not going to be installed
Recommends: r-base-html but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
I have run these commands to set up apt to receive R 4.0, as recommended at https://cran.r-project.org/bin/linux/ubuntu/README.html:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
sudo apt-get update
What am I doing wrong, and how can I fix it?
I did have R 3.4 installed on this system before, and removed it with
sudo apt-get remove r-*
sudo apt-get purge r-*
Have I screwed something up by doing that?
The error was, it turned out, entirely mine:
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
added the repo for Ubuntu 20.04. I needed:
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/'

Installing R devtools package on WSL

The problem:
I'm trying to install the devtools package for R. I'm using Ubuntu 18.04 LTS on WSL, the Windows Subsystem for Linux.
I'm able to install some packages just fine with a simple call to install.packages() from within R on WSL. However, other packages seem to give me trouble.
None of the following methods I've tried seem to work:
* I've tried installing the package with install.packages().
* I've tried installing from source into /usr/local/lib/R/site-library.
* I've tried installing from source into a personal library.
Error message:
I was recieving an error message like that discussed here, but I was unable to fix the problem by editing unpackPkgZip because it didn't exist.
The Question:
How can I install devtools on WSL?
Solution:
I was able to fix the problem by starting over. I uninstalled Ubuntu and then reinstalled it. With a fresh install of Ubuntu 18.04 I followed these instructions. There are other online tutorials which probably work just fine, but I followed this one. You can ignore the bit about installing an rstudio server and the fsl package if you wish.
# Install R on WSL
sudo apt-get update -qq -y
sudo apt-get install -y wget git
OS_DISTRIBUTION=$(lsb_release -cs)
wget -O- http://neuro.debian.net/lists/${OS_DISTRIBUTION}.us-nh.full | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list
sudo apt-key adv --recv-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9
sudo apt-get update
sudo apt-get install libopenblas-base r-base
sudo apt-get update -qq -y
sudo apt-get install -y libgit2-dev
sudo apt-get install -y libcurl4-openssl-dev libssl-dev
sudo apt-get install -y zlib1g-dev libssh2-1-dev libpq-dev libxml2-dev
#sudo apt-get install -y libhdf5 # This didn't work.
Now try installing devtools in R.
# Install devtools
install.packages("devtools", repos = "https://cran.rstudio.com/")
Permission error:
If you encounter a permission error like the following...
Warning in install.packages("edgeR") :'lib = "/usr/local/lib/R/site-library"' is not writable Would you like to use a personal library instead? (y/n)
...you need to provide the user with write access to the directory where R packages are installed (see here). Try changing the group ownership of this directory:
# Who has ownership of /usr/local/lib/R/site-library/?
ls -l /usr/local/lib/R/
# drwxrwsr-x 1 root staff 512 Jul 18 21:38 site-library
# Change ownership.
sudo chgrp twesleyb /usr/local/lib/R/site-library/
ls -l /usr/local/lib/R/
#drwxrwxr-x 1 root twesleyb 512 Jul 18 21:38 site-library
# In this case I have write access, but in case you need to add it, try:
# $ sudo chmod g+w /usr/local/lib/R/site-library
You should now be able to install.packages("package").
I'm a linux novice, but I think this is an okay thing to do.
Update:
You can also try following duckmayr's instructions.

How to upgrade R version on WSL?

I'm running Ubuntu in Windows Subsystem for Linux, and apt-get update isn't finding the newest versions of r-base. On Ubuntu 16.04, the newest R version it gets is 3.2.3. How do I upgrade to newer versions of R?
It turns out that the version of r-base in the default Ubuntu repository is behind the newest version of r-base from CRAN.
The solution is to add R-CRAN to /etc/apt/sources.list, using the instructions here: https://cran.r-project.org/bin/linux/ubuntu/
sudo sh -c 'echo "deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/" >> /etc/apt/sources.list'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo apt-get update
sudo apt-get install --only-upgrade r-base # This upgrades r-base if it's already installed; otherwise it doesn't install it
As #DirkEddelbuettel said in his comments, this README has helpful information for how you can update your R version in a Windows subsystem for Linux (WSL) setting. For me, I updated from R 3.4 to R 4.0 on Ubuntu 18.04.
I am running bionic (I used lsb_release -a to find out), and I wanted R 4.0 so I picked the appropriate deb line (for me: deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/) to add to my /etc/apt/sources.list file (had to use sudo vim /etc/apt/sources.list to add this line to the end). Then I ran sudo apt-get update and sudo apt-get install r-base. Now I have 4.0.2, the newest version. Just pick the particular Ubuntu/R combo that you want based on the options from the README. I hope this can help someone.

Why does apt-get install r-base install 3.2.3 instead of 3.4.0 in R?

I am trying to install the latest version of R (3.4.0) due to some incompatibility issues with dowloading of a package called "Slam". I have downloaded the tar.gz file of 3.4.0 but there are some issues with the make file for installation.
I have uninstalled the r-base of 3.2.3. Now when I'm installing R again, I get the same version instead of the upgrade version. I even ran the sudo apt-get update command but in vain.
you need to install from the CRAN repos not the ubuntu ones. add the key, then the repository, update and the apt-get
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

Resources