Load r package in linux

What is the preferred way to install R packages in Ubuntu?

I am installing in R in ubuntu, but I am a bit confused with the many options there are to install packages. The traditional way is to install them, inside R, by doing install.package() . Ubuntu however offers the possibility of installing with apt-get . This is interesting since the OS will keep packages updated. Since they have only a couple of packages available it will create problems sooner or later. I will eventually have install packages through the traditional way, having them installed in different ways, and maybe (?) this will also create version problems. What is the preferred way to install and keep R packages in Ubuntu?

4 Answers 4

I think the only R packages available through the Ubuntu repos are the packages maintained by the R development core team. Like with most packages, those available through apt or synaptic are not always the newest versions. Luckily you have the option of adding a CRAN-maintained software source by creating a new file at /etc/apt/sources.list.d/CRAN.list that contains a single line of text:

deb http://cran.r-project.org/bin/linux/ubuntu trusty/ 

(replace trusty/ with your distribution’s codename; if you don’t know it type lsb_release -c into a terminal). After that (and an apt update ) your package manager will always install (or update to) the CRAN-maintained versions of r-base , r-base-core , etc., because they will have higher version numbers than the ones in the debian sources. See here if apt complains about the repo being unsigned.

For all other packages (AKA «contributed packages»), I prefer to install within R via install.packages(c(«name_of_package», «name_of_other_package»)) whenever possible, unless I know for a fact that the version on CRAN is old and that a newer version has functionality that I need. In such cases you can install from GitHub with devtools::install_github(‘AccountName/RepositoryName’) or download an archive and install it from a terminal window via R CMD INSTALL name_of_package.tar.gz , or within R via install.packages(«/path/to/downloaded/package.tar.gz», repos=NULL, type=»source») .

Источник

Installing R

Package for the current R 4.2. release* are available for most stable Desktop releases of Ubuntu until their official end of life date. However, only the latest Long Term Support (LTS) release is fully supported. As of May 2, 2022 the supported releases are

  • Jammy Jellyfish (22.04, amd64 only)
  • Impish Indri (21.10, amd64 only),
  • Focal Fossa (20.04; LTS and amd64 only),
  • Bionic Beaver (18.04; LTS), and
  • Xenial Xerus (16.04; LTS).
Читайте также:  Посмотреть таблицу разделов linux

Note that in order to install R 4.1 packages, a new and different sources.list entry is needed. See below for details.

For older R releases, see the corresponding README.

Additional CRAN Packages

For additional binary packages for R (currently well over 4,000+), check out the different CRAN2deb4ubuntu PPAs. For R 4.1.*, this is https://launchpad.net/~c2d4u.team/+archive/ubuntu/c2d4u4.0+

The ‘c2d4u’ repository is only available for LTS releases. If you wish to attempt to use the repository with an non-LTS release, you can manually edit the ’c2d4u_team-ubuntu-c2d4u4_0_-*.list’ to use focal instead of the intended release. This usage of the ‘c2d4u’ repository is unsupported. An LTS release is strongly suggested for utilizing the ‘c2d4u’ repository.

Installation

To obtain the latest R 4.1 packages, add an entry like

deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/
deb https://cloud.r-project.org/bin/linux/ubuntu impish-cran40/
deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/
deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/
deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/

in your /etc/apt/sources.list file. By using https://cloud.r-project.org, you will be automatically be redirected to a nearby CRAN mirror. See https://cran.r-project.org/mirrors.html for the current list of CRAN mirrors.

To install the complete R system, use

sudo apt-get update sudo apt-get install r-base

Users who need to compile R packages from source [e.g. package maintainers, or anyone installing packages with install.packages()] should also install the r-base-dev package:

sudo apt-get install r-base-dev

The R packages for Ubuntu otherwise behave like the Debian ones. One may find additional information in the Debian README file located at https://cran.R-project.org/bin/linux/debian/.

Installation and compilation of R or some of its packages may require Ubuntu packages from the “backports” repositories. Therefore, it is suggested to activate the backports repositories with an entry like

deb https:/// focal-backports main restricted universe

in your /etc/apt/sources.list file. See https://launchpad.net/ubuntu/+archivemirrors for the list of Ubuntu mirrors.

Users of Mint and other derivatives of Ubuntu

When creating an entry for apt, you must use the Ubuntu release name your distribution is based on. For example, do not use “uma”, instead use “focal.”

Supported Packages

A number of R packages are available from the Ubuntu repositories with names starting with r-cran-. The following ones are kept up-to-date on CRAN: all packages part of the r-recommended bundle, namely

  • r-cran-boot
  • r-cran-class
  • r-cran-cluster
  • r-cran-codetools
  • r-cran-foreign
  • r-cran-kernsmooth
  • r-cran-lattice
  • r-cran-mass
  • r-cran-matrix
  • r-cran-mgcv
  • r-cran-nlme
  • r-cran-nnet
  • r-cran-rpart
  • r-cran-spatial
  • r-cran-survival
Читайте также:  Oracle linux firewall disabled

The other r-cran-* packages are updated with Ubuntu releases only. Users who need to update one of these R packages (say r-cran-foo) should first make sure to obtain all the required build dependencies with

sudo apt-get build-dep r-cran-foo

Because they rely on the installed version of R, we also provide, on an experimental basis, versions of the following packages as up-to-date as the Ubuntu release allows:

Please notice that the maintainers are not necessarily themselves users of these packages, so positive or negative feedback through the usual channels (see below) would be appreciated.

Finally, as an added convenience to Ubuntu users who interact with R through Emacs, we also provide an up-to-date version of the package

Secure APT

With the deprecation of apt-key, the recommended method for adding the key is:

wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

The fingerprint should be E298A3A825C0D65DFD57CBB651716619E084DAB9.

Using apt-key

NOTE: There was an issue with a second key found on the Ubuntu keyserver. Details and how to remove can be found at http://rubuntu.netlify.com/post/changes-to-cran-ubuntu-webpage-regarding-apt-secure-key/.

The Ubuntu archives on CRAN are signed with the key of “Michael Rutter marutter@gmail.com” with key ID 0x51716619e084dab9. To add the key to your system with one command use (thanks to Brett Presnell for the tip):

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

An alternate method can be used by retrieving the key with

gpg --keyserver keyserver.ubuntu.com --recv-key E298A3A825C0D65DFD57CBB651716619E084DAB9

and then feed it to apt-key with

gpg -a --export E298A3A825C0D65DFD57CBB651716619E084DAB9 | sudo apt-key add -

Some people have reported difficulties using this approach. The issue is usually related to a firewall blocking port 11371. If the first gpg command fails, you may want to try (thanks to Mischan Toosarani for the tip):

gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

and then feed it to apt-key with

gpg -a --export E298A3A825C0D65DFD57CBB651716619E084DAB9 | sudo apt-key add -

Another alternative approach is to search for the key at http://keyserver.ubuntu.com:11371/ and copy the key to a plain text file, say key.txt. Then, feed the key to apt-key with

Читайте также:  Linux increase partition size

Maintenance of R Packages

The R packages part of the Ubuntu r-base and r-recommended packages are installed into the directory /usr/lib/R/library. These can be updated using apt-get with

sudo apt-get update sudo apt-get upgrade

The other r-cran-* packages shipped with Ubuntu are installed into the directory /usr/lib/R/site-library.

Installing R packages not provided with Ubuntu first requires tools to compile the packages from source. These tools are installed via the R development package with

sudo apt-get install r-base-dev

This pulls in the basic requirements for compiling R packages. R packages may then be installed by the local user/admin from the CRAN source packages, typically from inside R using the

from a shell. If you have proper write permissions in /usr/local/lib/R/site-library/, and you have not set R_LIBS_USER manually, they will be installed there. Otherwise, you will be asked if a directory in your home directory should be created for these packages. A routine update of such locally compiled packages can be done using

which will update the packages in the first part of your library path. You can have a look at the components of this path by

If you would like to update R packages that have been installed via the Ubuntu package management system which are installed somewhere under /usr/lib/, I would recommend to do this the Ubuntu way using the source packages from the latest version of Ubuntu or use my PPA cran2deb4ubuntu — https://launchpad.net/~c2d4u.team/+archive/ubuntu/c2d4u4.0+.

Pathways to R Packages

In order to find packages, R looks at the variables R_LIBS_USER and R_LIBS_SITE. On Debian and Ubuntu, R_LIBS_USER is set in /etc/R/Renviron to

where $platform is something like ‘x86_64-pc-linux-gnu’ and depending on the version of R installed. You can override this in your ~/.Renviron. R_LIBS_SITE is set in /etc/R/Renviron to

This means that packages installed from within R take precedence over the ones installed via the Ubuntu package management system if you happen to have two versions installed at the same time.

Reporting Problems

The best place to report problems with these packages or ask R questions specific to Ubuntu is the R-SIG-Debian mailing list. See

Acknowledgements

The Debian R packages are maintained by Dirk Eddelbuettel. The Ubuntu packages are compiled for i386 and amd64 by Michael Rutter (marutter@gmail.com) using scripts developed by Vincent Goulet.

Источник

Оцените статью
Adblock
detector