Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Packages Takes A Very Long Time on Ubuntu

Tags:

installation

r

I was using Windows as OS and RStudio for windows, switched to Ubuntu today and installed R and RStudio again. When I try to install some packages from CRAN (only tidyverse !) using install.packages(), I see something something on console I have never seen on Windows, it looks like this;

* installing *source* package ‘data.table’ ...
** package ‘data.table’ successfully unpacked and MD5 sums checked
** using staged installation
gcc -std=gnu99 9.3.0
zlib 1.2.11 is available ok
OpenMP supported
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -fopenmp -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-5iUtQS/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c assign.c -o assign.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -fopenmp -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-5iUtQS/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c between.c -o between.o

...

then it continues like this and installing process is taking much longer than the time I encountered on Windows. (tidyverse which includes about seven packages took 30 minutes)

Is this normal ? if it is not, how can I solve it ?

like image 300
sametsokel Avatar asked Sep 09 '20 23:09

sametsokel


Video Answer


1 Answers

A summary of the comments that helped resolve the issue.


In general, the default installation method in linux is type="source", which means that any package with non-R source code (e.g., C++, Fortran) needs to be compiled. Further, CRAN and all of its repository mirrors only provide binary packages windows and macos.

It appears that there are two ways to install binary packages on linux vice the default:

  1. @duckmayr's suggestion to read https://cran.r-project.org/bin/linux/ubuntu/README.html (similar pages exist for other linux distros) identifies how to set up the CRAN2deb4ubuntu PPA, so that one can the the OS-level software management apt (and related tools). These ubuntu/debian packages are maintained well and reasonably up-to-date, though not nearly as frequently updated as a straight-shot to the CRAN servers.

    But instead of the long-running R command install.packages("tidyverse"), you can simply run this for a binary installation, same effect:

    $ sudo apt-get install r-cran-tidyverse
    

    Unfortunately, the PPA does not include every single contributed package supplied to CRAN (as that would take significant effort on the PPA maintainers' side, trying to keep up with CRAN's daily onslaught of new packages and package-updates ... the testing alone sounds prohibitive). (The number suggested is 4000+ packages in the PPA, out of CRAN's 16,278 packages (as of 30 seconds ago).

  2. A recent addition to the repository scene is RStudio's Public Package Manager. In a recent blog post, RStudio announced it to have (at least) three fundamental features:

    • Access to pre-compiled packages on Linux via install.packages ...
    • Historical checkpoints for CRAN enabling reproducible work ...
    • Expanded Windows support for older versions of R ...

    (That's just a small snapshot of the blog post, I suggest you read the original for more details and context.)

    A quick search (of packages for Ubuntu 20.04 Focal) reveals: 15,217 binary and 16,216 source packages.

    Borrowing from RStudio's "Setup" page, for Ubuntu 20.04 Focal you can set this as your repository with

    options(repos = c(PkgMgr="https://packagemanager.rstudio.com/all/__linux__/focal/latest"))
    

    (I named it "PkgMgr", that's arbitrary. You may want/need more repos, over to you, see ?options and ?setRepository. This is a sample only, provided for convenience; please go to RStudio's documentation for how to set up your R for your installation.)

like image 140
r2evans Avatar answered Oct 10 '22 09:10

r2evans