Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: apt-get install r-cran-foo vs. install.packages("foo")

When installing R packages (say mcmcpack in this example) under Ubuntu I have the choice between the following two methods of installation:

# Let the distribution's packaging system take care of installation/upgrades apt-get install r-cran-mcmcpack  # Let R take care of installation/upgrades install.packages("mcmcpack") 

Questions:

  • Is any of the two ways of installing R packages considered "best practice"?
  • Assume that I first install.packages("mcmcpack") and later on apt-get install r-cran-mcmcpack - should I expect trouble?
  • Assume that I first apt-get install r-cran-mcmcpack and later on install.packages("mcmcpack") - should I expect trouble?
like image 613
knorv Avatar asked Jan 31 '10 00:01

knorv


People also ask

What are R packages what is CRAN?

Comprehensive R Archive Network (CRAN) It contains an archive of the latest and previous versions of the R distribution, documentation, and contributed R packages. It includes both source packages and pre-compiled binaries for Windows and macOS. As of November 2020, more than 16,000 packages are available.

Do I need to install R packages every time?

You only need to install packages the first time you use R (or after updating to a new version). **R Tip:** You can just type this into the command line of R to install each package. Once a package is installed, you don't have to install it again while using the version of R!

How do I install a package from CRAN R?

Installing the CRAN packages with the menuIn RStudio go to Tools → Install Packages and in the Install from option select Repository (CRAN) and then specify the packages you want. In classic R IDE go to Packages → Install package(s) , select a mirror and install the package.


1 Answers

It's not as easy as it seems.

  • apt-get update is good if and when

    • packages exist -- but there are only around 150 or so r-cran-* packages out of a pool of 2100+ packages on CRAN, so rather sparse coverage

    • packages are maintained, bug free and current

    • you are happy enough with the bi-annual releases by Ubuntu

  • install.packages() and later update.packages() is good if and when

    • you know what it takes to have built-time dependencies (besides r-base-dev) installed

    • you don't mind running update.packages() by hand as well as the apt-get updates.

On my Ubuntu machine at work, I go with the second solution. But because the first one is better if you have enough coverage, we have built cran2deb which provides 2050+ binary deb packages for amd64 and i386 --- but only for Debian testing. That is what I use at home.

As for last question of whether you 'should you expect trouble': No, because R_LIBS_SITE is set in /etc/R/Renvironment to be

# edd Apr 2003  Allow local install in /usr/local, also add a directory for #               Debian packaged CRAN packages, and finally the default dir  # edd Jul 2007  Now use R_LIBS_SITE, not R_LIBS R_LIBS_SITE=${R_LIBS_SITE-'/usr/local/lib/R/site-library:\ /usr/lib/R/site-library:/usr/lib/R/library'} 

which means that your packages go into /usr/local/lib/R/site-library whereas those managed by apt go into /usr/lib/R/site-library and (in the case of base packages) /usr/lib/R/library.

Hope that clarifies matters. The r-sig-debian mailing list is a more informed place for questions like this.

like image 83
Dirk Eddelbuettel Avatar answered Sep 19 '22 23:09

Dirk Eddelbuettel