R Installation and Administration

Table of Contents

Next:   [Contents][Index]

R Installation and Administration

This is a guide to installation and administration for R.

This manual is for R, version 3.5.0 Under development (2017-12-15).

Copyright © 2001–2017 R Core Team

Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the R Core Team.


Next: , Previous: , Up: Top   [Contents][Index]

1 Obtaining R

Sources, binaries and documentation for R can be obtained via CRAN, the “Comprehensive R Archive Network” whose current members are listed at https://CRAN.R-project.org/mirrors.html.


Next: , Previous: , Up: Obtaining R   [Contents][Index]

1.1 Getting and unpacking the sources

The simplest way is to download the most recent R-x.y.z.tar.gz file, and unpack it with

tar -xf R-x.y.z.tar.gz

on systems that have a suitable1 tar installed. On other systems you need to have the gzip program installed, when you can use

gzip -dc R-x.y.z.tar.gz | tar -xf -

The pathname of the directory into which the sources are unpacked should not contain spaces, as most make programs (and specifically GNU make) do not expect spaces.

If you want the build to be usable by a group of users, set umask before unpacking so that the files will be readable by the target group (e.g., umask 022 to be usable by all users). Keep this setting of umask whilst building and installing.

If you use a recent GNU version of tar and do this as a root account (which on Windows includes accounts with administrator privileges) you may see many warnings about changing ownership. In which case you can use

tar --no-same-owner -xf R-x.y.z.tar.gz

and perhaps also include the option --no-same-permissions. (These options can also be set in the TAR_OPTIONS environment variable: if more than one option is included they should be separated by spaces.)


Previous: , Up: Obtaining R   [Contents][Index]

1.2 Getting patched and development versions

A patched version of the current release, ‘r-patched’, and the current development version, ‘r-devel’, are available as daily tarballs and via access to the R Subversion repository. (For the two weeks prior to the release of a minor (3.x.0) version, ‘r-patched’ tarballs may refer to beta/release candidates of the upcoming release, the patched version of the current release being available via Subversion.)

The tarballs are available from https://stat.ethz.ch/R/daily. Download R-patched.tar.gz or R-devel.tar.gz (or the .tar.bz2 versions) and unpack as described in the previous section. They are built in exactly the same way as distributions of R releases.


Previous: , Up: Getting patched and development versions   [Contents][Index]

1.2.1 Using Subversion and rsync

Sources are also available via https://svn.R-project.org/R/, the R Subversion repository. If you have a Subversion client (see https://subversion.apache.org/), you can check out and update the current ‘r-devel’ from https://svn.r-project.org/R/trunk/ and the current ‘r-patched’ from ‘https://svn.r-project.org/R/branches/R-x-y-branch/’ (where x and y are the major and minor number of the current released version of R). E.g., use

svn checkout https://svn.r-project.org/R/trunk/ path

to check out ‘r-devel’ into directory path (which will be created if necessary). The alpha, beta and RC versions of an upcoming x.y.0 release are available from ‘https://svn.r-project.org/R/branches/R-x-y-branch/’ in the four-week period prior to the release.

Note that ‘https:’ is required2, and that the SSL certificate for the Subversion server of the R project should be recognized as from a trusted source.

Note that retrieving the sources by e.g. wget -r or svn export from that URL will not work (and will give a error early in the make process): the Subversion information is needed to build R.

The Subversion repository does not contain the current sources for the recommended packages, which can be obtained by rsync or downloaded from CRAN. To use rsync to install the appropriate sources for the recommended packages, run ./tools/rsync-recommended from the top-level directory of the R sources.

If downloading manually from CRAN, do ensure that you have the correct versions of the recommended packages: if the number in the file VERSION is ‘x.y.z’ you need to download the contents of ‘https://CRAN.R-project.org/src/contrib/dir’, where dir is ‘x.y.z/Recommended’ for r-devel or x.y-patched/Recommended for r-patched, respectively, to directory src/library/Recommended in the sources you have unpacked. After downloading manually you need to execute tools/link-recommended from the top level of the sources to make the requisite links in src/library/Recommended. A suitable incantation from the top level of the R sources using wget might be (for the correct value of dir)

wget -r -l1 --no-parent -A\*.gz -nd -P src/library/Recommended \
  https://CRAN.R-project.org/src/contrib/dir
./tools/link-recommended

Next: , Previous: , Up: Top   [Contents][Index]

2 Installing R under Unix-alikes

R will configure and build under most common Unix and Unix-alike platforms including ‘cpu-*-linux-gnu’ for the ‘alpha’, ‘arm’, ‘hppa’, ‘ix86’, ‘m68k’, ‘mips’, ‘mipsel’, ‘powerpc’, ‘s390’, ‘sparc’, and ‘x86_64CPUs, ‘x86_64-apple-darwin’, ‘i386-sun-solaris’ and ‘sparc-sun-solaris’ as well as perhaps (it is tested less frequently on these platforms) ‘i386-apple-darwin’, ‘i386-*-freebsd’, ‘x86_64-*-freebsd’, ‘i386-*-netbsd’, ‘x86_64/*-openbsd’ and ‘powerpc-ibm-aix6*

In addition, binary distributions are available for some common Linux distributions and for macOS (formerly OS X and Mac OS). See the FAQ for current details. These are installed in platform-specific ways, so for the rest of this chapter we consider only building from the sources.

Cross-building is not possible: installing R builds a minimal version of R and then runs many R scripts to complete the build.


Next: , Previous: , Up: Installing R under Unix-alikes   [Contents][Index]

2.1 Simple compilation

First review the essential and useful tools and libraries in Essential and useful other programs under a Unix-alike, and install those you want or need. Ensure that the environment variable TMPDIR is either unset (and /tmp exists and can be written in and scripts can be executed from) or points to the absolute path to a valid temporary directory (one from which execution of scripts is allowed) which does not contain spaces.3

Choose a directory to install the R tree (R is not just a binary, but has additional data sets, help files, font metrics etc). Let us call this place R_HOME. Untar the source code. This should create directories src, doc, and several more under a top-level directory: change to that top-level directory (At this point North American readers should consult Setting paper size.) Issue the following commands:

./configure
make

(See Using make if your make is not called ‘make’.) Users of Debian-based 64-bit systems4 may need

./configure LIBnn=lib
make

Then check the built system works correctly by

make check

Failures are not necessarily problems as they might be caused by missing functionality, but you should look carefully at any reported discrepancies. (Some non-fatal errors are expected in locales that do not support Latin-1, in particular in true C locales and non-UTF-8 non-Western-European locales.) A failure in tests/ok-errors.R may indicate inadequate resource limits (see Running R).

More comprehensive testing can be done by

make check-devel

or

make check-all

see file tests/README and Testing a Unix-alike Installation for the possibilities of doing this in parallel. Note that these checks are only run completely if the recommended packages are installed.

If the configure and make commands execute successfully, a shell-script front-end called R will be created and copied to R_HOME/bin. You can link or copy this script to a place where users can invoke it, for example to /usr/local/bin/R. You could also copy the man page R.1 to a place where your man reader finds it, such as /usr/local/man/man1. If you want to install the complete R tree to, e.g., /usr/local/lib/R, see Installation. Note: you do not need to install R: you can run it from where it was built.

You do not necessarily have to build R in the top-level source directory (say, TOP_SRCDIR). To build in BUILDDIR, run

cd BUILDDIR
TOP_SRCDIR/configure
make

and so on, as described further below. This has the advantage of always keeping your source tree clean and is particularly recommended when you work with a version of R from Subversion. (You may need GNU make to allow this, and you will need no spaces in the path to the build directory. It is unlikely to work if the source directory has previously been used for a build.)

Now rehash if necessary, type R, and read the R manuals and the R FAQ (files FAQ or doc/manual/R-FAQ.html, or https://CRAN.R-project.org/doc/FAQ/R-FAQ.html which always has the version for the latest release of R).

Note: if you already have R installed, check that where you installed R replaces or comes earlier in your path than the previous installation. Some systems are set up to have /usr/bin (the standard place for a system installation) ahead of /usr/local/bin (the default place for installation of R) in their default path, and some do not have /usr/local/bin on the default path.


Next: , Previous: , Up: Installing R under Unix-alikes   [Contents][Index]

2.2 Help options

By default HTML help pages are created when needed rather than being built at install time.

If you need to disable the server and want HTML help, there is the option to build HTML pages when packages are installed (including those installed with R). This is enabled by the configure option --enable-prebuilt-html. Whether R CMD INSTALL (and hence install.packages) pre-builds HTML pages is determined by looking at the R installation and is reported by R CMD INSTALL --help: it can be overridden by specifying one of the INSTALL options --html or --no-html.

The server is disabled by setting the environment variable R_DISABLE_HTTPD to a non-empty value, either before R is started or within the R session before HTML help (including help.start) is used. It is also possible that system security measures will prevent the server from being started, for example if the loopback interface has been disabled. See ?tools::startDynamicHelp for more details.


Next: , Previous: , Up: Installing R under Unix-alikes   [Contents][Index]

2.3 Making the manuals

There is a set of manuals that can be built from the sources,

fullrefman

Printed versions of all the help pages for base and recommended packages (around 3500 pages).

refman

Printed versions of the help pages for selected base packages (around 2000 pages)

R-FAQ

R FAQ

R-intro

“An Introduction to R”.

R-data

“R Data Import/Export”.

R-admin

“R Installation and Administration”, this manual.

R-exts

“Writing R Extensions”.

R-lang

“The R Language Definition”.

To make these (with ‘fullrefman’ rather than ‘refman’), use

make pdf      to create PDF versions
make info     to create info files (not ‘refman’ nor ‘fullrefman’).

You will not be able to build any of these unless you have texi2any version 5.1 or later installed, and for PDF you must have texi2dvi and texinfo.tex installed (which are part of the GNU texinfo distribution but are, especially texinfo.tex, often made part of the TeX package in re-distributions). For historical reasons, the path to texi2any can be set by macro ‘MAKEINFO’ in config.site (makeinfo is nowadays a link to texi2any).

The PDF versions can be viewed using any recent PDF viewer: they have hyperlinks that can be followed. The info files are suitable for reading online with Emacs or the standalone GNU info program. The PDF versions will be created using the paper size selected at configuration (default ISO a4): this can be overridden by setting R_PAPERSIZE on the make command line, or setting R_PAPERSIZE in the environment and using make -e. (If re-making the manuals for a different paper size, you should first delete the file doc/manual/version.texi. The usual value for North America would be ‘letter’.)

There are some issues with making the PDF reference manual, fullrefman.pdf or refman.pdf. The help files contain both ISO Latin1 characters (e.g. in text.Rd) and upright quotes, neither of which are contained in the standard LaTeX Computer Modern fonts. We have provided four alternatives:

times

(The default.) Using standard PostScript fonts, Times Roman, Helvetica and Courier. This works well both for on-screen viewing and for printing. One disadvantage is that the Usage and Examples sections may come out rather wide: this can be overcome by using in addition either of the options inconsolata (on a Unix-alike only if found by configure) or beramono, which replace the Courier monospaced font by Inconsolata or Bera Sans mono respectively. (You will need a recent version of the appropriate LaTeX package inconsolata5 or bera installed.)

Note that in most LaTeX installations this will not actually use the standard fonts for PDF, but rather embed the URW clones NimbusRom, NimbusSans and (for Courier, if used) NimbusMon.

This needs LaTeX packages times, helvetic and (if used) courier installed.

lm

Using the Latin Modern fonts. These are not often installed as part of a TeX distribution, but can obtained from https://www.ctan.org/tex-archive/fonts/ps-type1/lm/ and mirrors. This uses fonts rather similar to Computer Modern, but is not so good on-screen as times.

cm-super

Using type-1 versions of the Computer Modern fonts by Vladimir Volovich. This is a large installation, obtainable from https://www.ctan.org/tex-archive/fonts/ps-type1/cm-super/ and its mirrors. These type-1 fonts have poor hinting and so are nowhere near as readable on-screen as the other three options.

ae

A package to use composites of Computer Modern fonts. This works well most of the time, and its PDF is more readable on-screen than the previous two options. There are three fonts for which it will need to use bitmapped fonts, tctt0900.600pk, tctt1000.600pk and tcrm1000.600pk. Unfortunately, if those files are not available, Acrobat Reader will substitute completely incorrect glyphs so you need to examine the logs carefully.

The default can be overridden by setting the environment variable R_RD4PDF. (On Unix-alikes, this will be picked up at install time and stored in etc/Renviron, but can still be overridden when the manuals are built, using make -e.) The usual6 default value for R_RD4PDF is ‘times,inconsolata,hyper’: omit ‘hyper’ if you do not want hyperlinks (e.g. for printing the manual) or do not have LaTeX package hyperref, and omit ‘inconsolata’ if you do not have LaTeX package inconsolata installed.

Further options, e.g for hyperref, can be included in a file Rd.cfg somewhere on your LaTeX search path. For example, if you prefer the text and not the page number in the table of contents to be hyperlinked use

\ifthenelse{\boolean{Rd@use@hyper}}{\hypersetup{linktoc=section}}{}

or

\ifthenelse{\boolean{Rd@use@hyper}}{\hypersetup{linktoc=all}}{}

to hyperlink both text and page number.

Ebook versions of most of the manuals in one or both of .epub and .mobi formats can be made by running in doc/manual one of

make ebooks
make epub
make mobi

This requires ebook-convert from Calibre (http://calibre-ebook.com/download), or from most Linux distributions. If necessary the path to ebook-convert can be set as make macro EBOOK to by editing doc/manual/Makefile (which contains a commented value suitable for macOS).


Next: , Previous: , Up: Installing R under Unix-alikes   [Contents][Index]

2.4 Installation

To ensure that the installed tree is usable by the right group of users, set umask appropriately (perhaps to ‘022’) before unpacking the sources and throughout the build process.

After

./configure
make
make check

(or, when building outside the source, TOP_SRCDIR/configure, etc) have been completed successfully, you can install the complete R tree to your system by typing

make install

A parallel make can be used (but run make before make install). Those using GNU make 4.0 or later may want to use make -j n -O to avoid interleaving of output.

This will install to the following directories:

prefix/bin or bindir

the front-end shell script and other scripts and executables

prefix/man/man1 or mandir/man1

the man page

prefix/LIBnn/R or libdir/R

all the rest (libraries, on-line help system, …). Here LIBnn is usually ‘lib’, but may be ‘lib64’ on some 64-bit Linux systems. This is known as the R home directory.

where prefix is determined during configuration (typically /usr/local) and can be set by running configure with the option --prefix, as in

./configure --prefix=/where/you/want/R/to/go

where the value should be an absolute path. This causes make install to install the R script to /where/you/want/R/to/go/bin, and so on. The prefix of the installation directories can be seen in the status message that is displayed at the end of configure. The installation may need to be done by the owner of prefix, often a root account.

You can install into another directory tree by using

make prefix=/path/to/here install

at least with GNU or Solaris make (but not some older Unix makes).

More precise control is available at configure time via options: see configure --help for details. (However, most of the ‘Fine tuning of the installation directories’ options are not used by R.)

Configure options --bindir and --mandir are supported and govern where a copy of the R script and the man page are installed.

The configure option --libdir controls where the main R files are installed: the default is ‘eprefix/LIBnn’, where eprefix is the prefix used for installing architecture-dependent files, defaults to prefix, and can be set via the configure option --exec-prefix.

Each of bindir, mandir and libdir can also be specified on the make install command line (at least for GNU make).

The configure or make variables rdocdir and rsharedir can be used to install the system-independent doc and share directories to somewhere other than libdir. The C header files can be installed to the value of rincludedir: note that as the headers are not installed into a subdirectory you probably want something like rincludedir=/usr/local/include/R-3.5.0.

If you want the R home to be something other than libdir/R, use rhome: for example

make install rhome=/usr/local/lib64/R-3.5.0

will use a version-specific R home on a non-Debian Linux 64-bit system.

If you have made R as a shared/static library you can install it in your system’s library directory by

make prefix=/path/to/here install-libR

where prefix is optional, and libdir will give more precise control.7 However, you should not install to a directory mentioned in LDPATHS (e.g. /usr/local/lib64) if you intend to work with multiple versions of R, since that directory may be given precedence over the lib directory of other R installations.

make install-strip

will install stripped executables, and on platforms where this is supported, stripped libraries in directories lib and modules and in the standard packages.

Note that installing R into a directory whose path contains spaces is not supported, and some aspects (such as installing source packages) will not work.

To install info and PDF versions of the manuals, use one or both of

make install-info
make install-pdf

Once again, it is optional to specify prefix, libdir or rhome (the PDF manuals are installed under the R home directory). (make install-info needs Perl installed if there is no command install-info on the system.)

More precise control is possible. For info, the setting used is that of infodir (default prefix/info, set by configure option --infodir). The PDF files are installed into the R doc tree, set by the make variable rdocdir.

A staged installation is possible, that it is installing R into a temporary directory in order to move the installed tree to its final destination. In this case prefix (and so on) should reflect the final destination, and DESTDIR should be used: see https://www.gnu.org/prep/standards/html_node/DESTDIR.html.

You can optionally install the run-time tests that are part of make check-all by

make install-tests

which populates a tests directory in the installation.


Next: , Previous: , Up: Installing R under Unix-alikes   [Contents][Index]

2.5 Uninstallation

You can uninstall R by

make uninstall

optionally specifying prefix etc in the same way as specified for installation.

This will also uninstall any installed manuals. There are specific targets to uninstall info and PDF manuals in file doc/manual/Makefile.

Target uninstall-tests will uninstall any installed tests, as well as removing the directory tests containing the test results.

An installed shared/static libR can be uninstalled by

make prefix=/path/to/here uninstall-libR

Next: , Previous: , Up: Installing R under Unix-alikes   [Contents][Index]

2.6 Sub-architectures

Some platforms can support closely related builds of R which can share all but the executables and dynamic objects. Examples include builds under Linux and Solaris for different CPUs or 32- and 64-bit builds.

R supports the idea of architecture-specific builds, specified by adding ‘r_arch=name’ to the configure line. Here name can be anything non-empty, and is used to name subdirectories of lib, etc, include and the package libs subdirectories. Example names from other software are the use of sparcv9 on Sparc Solaris and 32 by gcc on ‘x86_64’ Linux.

If you have two or more such builds you can install them over each other (and for 32/64-bit builds on one architecture, one build can be done without ‘r_arch’). The space savings can be considerable: on ‘x86_64’ Linux a basic install (without debugging symbols) took 74Mb, and adding a 32-bit build added 6Mb. If you have installed multiple builds you can select which build to run by

R --arch=name

and just running ‘R’ will run the last build that was installed.

R CMD INSTALL will detect if more than one build is installed and try to install packages with the appropriate library objects for each. This will not be done if the package has an executable configure script or a src/Makefile file. In such cases you can install for extra builds by

R --arch=name CMD INSTALL --libs-only pkg1 pkg2

If you want to mix sub-architectures compiled on different platforms (for example ‘x86_64’ Linux and ‘i686’ Linux), it is wise to use explicit names for each, and you may also need to set libdir to ensure that they install into the same place.

When sub-architectures are used the version of Rscript in e.g. /usr/bin will be the last installed, but architecture-specific versions will be available in e.g. /usr/lib64/R/bin/exec${R_ARCH}. Normally all installed architectures will run on the platform so the architecture of Rscript itself does not matter. The executable Rscript will run the R script, and at that time the setting of the R_ARCH environment variable determines the architecture which is run.

When running post-install tests with sub-architectures, use

R --arch=name CMD make check[-devel|all]

to select a sub-architecture to check.

Sub-architectures are also used on Windows, but by selecting executables within the appropriate bin directory, R_HOME/bin/i386 or R_HOME/bin/x64. For backwards compatibility there are executables R_HOME/bin/R.exe and R_HOME/bin/Rscript.exe: these will run an executable from one of the subdirectories, which one being taken first from the R_ARCH environment variable, then from the --arch command-line option8 and finally from the installation default (which is 32-bit for a combined 32/64 bit R installation).


Previous: , Up: Sub-architectures   [Contents][Index]

2.6.1 Multilib

For some Linux distributions9, there is an alternative mechanism for mixing 32-bit and 64-bit libraries known as multilib. If the Linux distribution supports multilib, then parallel builds of R may be installed in the sub-directories lib (32-bit) and lib64 (64-bit). The build to be run may then be selected using the setarch command. For example, a 32-bit build may be run by

setarch i686 R

The setarch command is only operational if both 32-bit and 64-bit builds are installed. If there is only one installation of R, then this will always be run regardless of the architecture specified by the setarch command.

There can be problems with installing packages on the non-native architecture. It is a good idea to run e.g. setarch i686 R for sessions in which packages are to be installed, even if that is the only version of R installed (since this tells the package installation code the architecture needed).

There is a potential problem with packages using Java, as the post-install for a ‘i686’ RPM on ‘x86_64’ Linux reconfigures Java and will find the ‘x86_64’ Java. If you know where a 32-bit Java is installed you may be able to run (as root)

export JAVA_HOME=<path to jre directory of 32-bit Java>
setarch i686 R CMD javareconf

to get a suitable setting.

When this mechanism is used, the version of Rscript in e.g. /usr/bin will be the last installed, but an architecture-specific version will be available in e.g. /usr/lib64/R/bin. Normally all installed architectures will run on the platform so the architecture of Rscript does not matter.


Next: , Previous: , Up: Installing R under Unix-alikes   [Contents][Index]

2.7 Other Options

There are many other installation options, most of which are listed by configure --help. Almost all of those not listed elsewhere in this manual are either standard autoconf options not relevant to R or intended for specialist uses by the R developers.

One that may be useful when working on R itself is the option --disable-byte-compiled-packages, which ensures that the base and recommended packages are not byte-compiled. (Alternatively the (make or environment) variable R_NO_BASE_COMPILE can be set to a non-empty value for the duration of the build.)

Option --with-internal-tzcode makes use of R’s own code and copy of the Olson database for managing timezones. This will be preferred where there are issues with the system implementation, usually involving times after 2037 or before 1916. An alternative time-zone directory10 can be used, pointed to by environment variable TZDIR: this should contain files such as Europe/London. On all tested OSes the system timezone was deduced correctly, but if necessary it can be set as the value of environment variable TZ.


Next: , Previous: , Up: Other Options   [Contents][Index]

2.7.1 OpenMP Support

By default configure searches for suitable options11 for OpenMP support for the C, C++98, FORTRAN 77 and Fortran compilers.

Only the C result is currently used for R itself, and only if MAIN_LD/DYLIB_LD were not specified. This can be overridden by specifying

R_OPENMP_CFLAGS

Use for packages has similar restrictions (involving SHLIB_LD and similar: note that as FORTRAN 77 code is normally linked by the C compiler, both need to support OpenMP) and can be overridden by specifying some of

SHLIB_OPENMP_CFLAGS
SHLIB_OPENMP_CXXFLAGS
SHLIB_OPENMP_FCFLAGS
SHLIB_OPENMP_FFLAGS

Setting to an empty value will disable OpenMP for that compiler (and configuring with --disable-openmp will disable all detection of OpenMP). The configure detection test is to compile and link a standalone OpenMP program, which is not the same as compiling a shared object and loading it into the C program of R’s executable. Note that overridden values are not tested.


Previous: , Up: Other Options   [Contents][Index]

2.7.2 C++ Support

C++ is not used by R itself, but support is provided for installing packages with C++ code via make macros defined in file etc/Makeconf (and with explanations in file config.site):

CXX
CXXFLAGS
CXXPICFLAGS
CXXSTD

CXX98
CXX98STD
CXX98FLAGS
CXX98PICFLAGS

CXX11
CXX11STD
CXX11FLAGS
CXX11PICFLAGS

CXX14
CXX14STD
CXX14FLAGS
CXX14PICFLAGS

CXX17
CXX17STD
CXX17FLAGS
CXX17PICFLAGS

The macros CXX etc are those used by default for C++ code. configure will attempt to set the rest suitably, choosing for CXX11STD a suitable flag such as -std=c++11 for C++11 support. Similarly, configure will if possible choose for CXX14STD a flag12 such as -std=c++14 for C++14 support and -std=c++1z for support for the forthcoming C++17 standard. The inferred values can be overridden in file config.site or on the configure command line: user-supplied values will be tested compiling some C++11/14/17 code.

R versions 3.1.0 to 3.3.3 used CXX1X rather than CXX11, and these forms are deprecated but still accepted.

It may be13 that there is no suitable flag for C++11 support, in which case a different compiler could be selected for CXX11 and its corresponding flags. Likewise, a different compiler can be specified for C++14 support with CXX14 and for C++17 support with CXX17. Some compilers14 by default assume a later standard than C++98 whereas the latter is assumed by some packages. So users of GCC 6 might like to specify

CXX='g++ -std=gnu++98'
CXX11=g++
CXX11STD='-std=c++11'
CXX14=g++
CXX14STD='-std=c++14'

The -std flag is supported by the GCC, clang, Intel and Solaris compilers (the latter from version 12.4). Currently accepted values are (plus some synonyms)

g++:     c++98 gnu++98 c++11 gnu+11 c++14 gnu++14 c++1z gnu++1z
Intel:   gnu+98 c++11 c++14 (from 16.0) c++17 (from 17.0)
Solaris: c++03 c++11 c++14 (from 12.5)

(Those for clang++ are not documented, but seem to be based on g++.) Versions 4.3.x to 4.8.x of g++ accepted flag -std=c++0x with partial support15 for C++11: this is currently still accepted as a deprecated synonym for -std=c++11. (At least for versions 4.8.x it has sufficient support to be picked by configure.) Option -std=c++14 was introduced in version 5.x.

‘Standards’ for g++ starting with ‘gnu’ enable ‘GNU extensions’: what those are is hard to track down.

For the use of C++11 and later in R packages see the ‘Writing R Extensions’ manual.


Previous: , Up: Installing R under Unix-alikes   [Contents][Index]

2.8 Testing an Installation

Full post-installation testing is possible only if the test files have been installed with

make install-tests

which populates a tests directory in the installation.

If this has been done, two testing routes are available. The first is to move to the home directory of the R installation (as given by R.home()) and run

cd tests
## followed by one of
../bin/R CMD make check
../bin/R CMD make check-devel
../bin/R CMD make check-all

and other useful targets are test-BasePackages and test-Recommended to run tests of the standard and recommended packages (if installed) respectively.

This re-runs all the tests relevant to the installed R (including for example code in the package vignettes), but not for example the ones checking the example code in the manuals nor making the standalone Rmath library. This can occasionally be useful when the operating environment has been changed, for example by OS updates or by substituting the BLAS (see Shared BLAS).

Parallel checking of packages may be possible: set the environment variable TEST_MC_CORES to the maximum number of processes to be run in parallel. This affects both checking the package examples (part of make check) and package sources (part of make check-devel and make check-recommended). It does require a make command which supports the make -j n option: most do but on Solaris you need to select GNU make or dmake. Where parallel checking of package sources is done, a log file pngname.log is left in the tests directory for inspection.

Alternatively, the installed R can be run, preferably with --vanilla. Then

Sys.setenv(LC_COLLATE = "C", LC_TIME = "C", LANGUAGE = "en")
tools::testInstalledBasic("both")
tools::testInstalledPackages(scope = "base")
tools::testInstalledPackages(scope = "recommended")

runs the basic tests and then all the tests on the standard and recommended packages. These tests can be run from anywhere: the basic tests write their results in the tests folder of the R home directory and run fewer tests than the first approach: in particular they do not test things which need Internet access—that can be tested by

tools::testInstalledBasic("internet")

These tests work best if diff (in Rtools*.exe for Windows users) is in the path.

It is possible to test the installed packages (but not their package-specific tests) by testInstalledPackages even if make install-tests was not run.

Note that the results may depend on the language set for times and messages: for maximal similarity to reference results you may want to try setting (before starting the R session)

LANGUAGE=en

and use a UTF-8 or Latin-1 locale.


Next: , Previous: , Up: Top   [Contents][Index]

3 Installing R under Windows

The bin/windows directory of a CRAN site contains binaries for a base distribution and a large number of add-on packages from CRAN to run on 32- or 64-bit Windows (Windows 7 and later are tested; XP is known to fail some tests) on ‘ix86’ and ‘x86_64CPUs.

Your file system must allow long file names (as is likely except perhaps for some network-mounted systems). If it doesn’t also support conversion to short name equivalents (a.k.a. DOS 8.3 names), then R must be installed in a path that does not contain spaces.

Installation is via the installer R-devel-win.exe. Just double-click on the icon and follow the instructions. When installing on a 64-bit version of Windows the options will include 32- or 64-bit versions of R (and the default is to install both). You can uninstall R from the Control Panel.

Note that you will be asked to choose a language for installation, and that choice applies to both installation and un-installation but not to running R itself.

See the R Windows FAQ for more details on the binary installer.


Next: , Previous: , Up: Installing R under Windows   [Contents][Index]

3.1 Building from source

R can be built as either a 32-bit or 64-bit application on Windows: to build the 64-bit application you need a 64-bit edition of Windows: such an OS can also be used to build 32-bit R.

The standard installer combines 32-bit and 64-bit builds into a single executable which can then be installed into the same location and share all the files except the .exe and .dll files and some configuration files in the etc directory.

Building is only tested in a 8-bit locale: using a multi-byte locale (as used for CJK languages) is unsupported and may not work (the scripts do try to select a ‘C’ locale; Windows may not honour this).

NB: The build process is currently being changed to require external binary distributions of third-party software. Their location is set using macro EXT_LIBS with default setting $(LOCAL_SOFT); the $(LOCAL_SOFT) macro defaults to $(R_HOME)/extsoft. This directory can be populated using make rsync-extsoft. The location can be overridden by setting EXT_LIBS to a different path in src/gnuwin32/MkRules.local. A suitable collection of files can also be obtained from https://CRAN.R-project.org/bin/windows/extsoft or https://www.stats.ox.ac.uk/pub/Rtools/libs.html.


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.1 Getting the tools

If you want to build R from the sources, you will first need to collect, install and test an extensive set of tools. See The Windows toolset (and perhaps updates in https://CRAN.R-project.org/bin/windows/Rtools/) for details.

The Rtools*.exe executable installer described in The Windows toolset also includes some source files in addition to the R source as noted below. You should run it first, to obtain a working tar and other necessities. Choose a “Full installation”, and install the extra files into your intended R source directory, e.g. C:/R. The directory name should not contain spaces. We will call this directory R_HOME below.


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.2 Getting the source files

You need to collect the following sets of files:

The following additional item is normally installed by Rtools*.exe. If instead you choose to do a completely manual build you will also need


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.3 Building the core files

Set the environment variable TMPDIR to the absolute path to a writable directory, with a path specified with forward slashes and no spaces. (The default is /tmp, which may not be useful on Windows.)

You may need to compile under a case-honouring file system: we found that a samba-mounted file system (which maps all file names to lower case) did not work.

Open a command window at R_HOME/src/gnuwin32, then run

make all recommended vignettes

and sit back and wait while the basic compile takes place.

Notes:


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.4 Building the cairo devices

The devices based on cairographics (svg, cairo_pdf, cairo_ps and the type = "cairo" versions of png, jpeg, tiff and bmp) are implemented in a separate DLL winCairo.dll which is loaded when one of these devices is first used. It is not built by default, and needs to be built (after make all) by make cairodevices.

To enable the building of these devices you need to install the static cairographics libraries built by Simon Urbanek at https://www.rforge.net/Cairo/files/cairo-current-win.tar.gz. Set the macro ‘CAIRO_HOME’ in MkRules.local. (Note that this tarball unpacks with a top-level directory src/: ‘CAIRO_HOME’ needs to include that directory in its path.)


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.5 Using ICU for collation

It is recommended to build R to support ICU (International Components for Unicode, http://site.icu-project.org/) for collation, as is commonly done on Unix-alikes.

Two settings are needed in MkRules.local,

# set to use ICU
# USE_ICU = YES
# path to parent of ICU headers
ICU_PATH = /path/to/ICU

The first should be uncommented and the second set to the top-level directory of a suitably packaged binary build of ICU, for example that at https://www.stats.ox.ac.uk/pub/Rtools/goodies/ICU_531.zip. Depending on the build, it may be necessary to edit the macro ICU_LIBS.

Unlike on a Unix-alike, it is normally necessary to call icuSetCollate to set a locale before ICU is actually used for collation, or set the environment variable R_ICU_LOCALE.


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.6 Support for libcurl

libcurl version 7.28.0 or later is used to support curlGetHeaders and the "libcurl" methods of download.file and url.

A suitable distribution can be found via https://www.stats.ox.ac.uk/pub/Rtools/libs.html and its unpacked location should be specified in file MkRules.local.

For secure use of e.g. ‘https://’ URLs Windows users may need to specify the path to up-to-date CA root certificates: see ?download.file.


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.7 Checking the build

You can test a build by running

make check

The recommended packages can be checked by

make check-recommended

Other levels of checking are

make check-devel

for a more thorough check of the R functionality, and

make check-all

for both check-devel and check-recommended.

If a test fails, there will almost always be a .Rout.fail file in the directory being checked (often tests/Examples or tests): examine the file to help pinpoint the problem.

Parallel checking of package sources (part of make check-devel and make check-recommended) is possible: see the environment variable TEST_MC_CORES to the maximum number of processes to be run in parallel.


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.8 Building the manuals

The PDF manuals require texinfo 5.1 or later, and can be made by

make manuals

If you want to make the info versions (not including the Reference Manual), use

cd ../../doc/manual
make -f Makefile.win info

(all assuming you have pdftex/pdflatex installed and in your path).

See the Making the manuals section in the Unix-alike section for setting options such as the paper size and the fonts used.

By default it is assumed that texinfo is not installed, and the manuals will not be built. The comments in file MkRules.dist describe settings to build them. (Copy that file to MkRules.local and edit it.) The texinfo 5.x package for use on Windows is available at https://www.stats.ox.ac.uk/pub/Rtools/: you will also need to install Perl16


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.9 Building the Inno Setup installer

You need to have the files for a complete R build, including bitmap and Tcl/Tk support and the manuals (which requires texinfo installed), as well as the recommended packages and Inno Setup (see The Inno Setup installer).

Once everything is set up

make distribution
make check-all

will make all the pieces and the installer and put them in the gnuwin32/cran subdirectory, then check the build. This works by building all the parts in the sequence:

rbuild (the executables, the FAQ docs etc.)
rpackages (the base packages)
htmldocs (the HTML documentation)
cairodevices (the cairo-based graphics devices)
recommended (the recommended packages)
vignettes (the vignettes in base packages:
	   only needed if building from an svn checkout)
manuals (the PDF manuals)
rinstaller (the install program)
crandir (the CRAN distribution directory, only for 64-bit builds)

The parts can be made individually if a full build is not needed, but earlier parts must be built before later ones. (The Makefile doesn’t enforce this dependency—some build targets force a lot of computation even if all files are up to date.) The first four targets are the default build if just make (or make all) is run.

Parallel make is not supported and likely to fail.

If you want to customize the installation by adding extra packages, replace make rinstaller by something like

make rinstaller EXTRA_PKGS='pkg1 pkg2 pkg3'

An alternative way to customize the installer starting with a binary distribution is to first make an installation of R from the standard installer, then add packages and make other customizations to that installation. Then (after having customized file MkRules, possibly via MkRules.local, and having made R in the source tree) in src/gnuwin32/installer run

make myR IMAGEDIR=rootdir

where rootdir is the path to the root of the customized installation (in double quotes if it contains spaces or backslashes).

Both methods create an executable with a standard name such as R-devel-win.exe, so please rename it to indicate that it is customized. If you intend to distribute a customized installer please do check that license requirements are met – note that the installer will state that the contents are distributed under GPL and this has a requirement for you to supply the complete sources (including the R sources even if you started with a binary distribution of R, and also the sources of any extra packages (including their external software) which are included).

The defaults for the startup parameters may also be customized. For example

make myR IMAGEDIR=rootdir MDISDI=1

will create an installer that defaults to installing R to run in SDI mode. See src/gnuwin32/installer/Makefile for the names and values that can be set.

The standard CRAN distribution of a 32/64-bit installer is made by first building 32-bit R (just

make 32-bit

is needed), and then (in a separate directory) building 64-bit R with the macro HOME32 set in file MkRules.local to the top-level directory of the 32-bit build. Then the make rinstaller step copies the files that differ between architectures from the 32-bit build as it builds the installer image.


Next: , Previous: , Up: Building from source   [Contents][Index]

3.1.10 Building the MSI installer

It is also possible to build an installer for use with Microsoft Installer. This is intended for use by sysadmins doing automated installs, and is not recommended for casual use.

It makes use of the Windows Installer XML (WiX) toolkit version 3.5 (or perhaps later, untested) available from http://wixtoolset.org/. Once WiX is installed, set the path to its home directory in MkRules.local.

You need to have the files for a complete R build, including bitmap and Tcl/Tk support and the manuals, as well as the recommended packages. There is no option in the installer to customize startup options, so edit etc/Rconsole and etc/Rprofile.site to set these as required. Then

cd installer
make msi

which will result in a file with a name like R-devel-win32.msi. This can be double-clicked to be installed, but those who need it will know what to do with it (usually by running msiexec /i with additional options). Properties that users might want to set from the msiexec command line include ‘ALLUSERS’, ‘INSTALLDIR’ (something like c:\Program Files\R\R-devel) and ‘RMENU’ (the path to the ‘R’ folder on the start menu) and ‘STARTDIR’ (the starting directory for R shortcuts, defaulting to something like c:\Users\name\Documents\R).

The MSI installer can be built both from a 32-bit build of R (R-devel-win32.msi) and from a 64-bit build of R (R-devel-win64.msi, optionally including 32-bit files by setting the macro HOME32, when the name is R-devel-win.msi). Unlike the main installer, a 64-bit MSI installer can only be run on 64-bit Windows.

Thanks to David del Campo (Dept of Statistics, University of Oxford) for suggesting WiX and building a prototype installer.


Previous: , Up: Building from source   [Contents][Index]

3.1.11 64-bit Windows builds

To build a 64-bit version of R you need a 64-bit toolchain: the only one discussed here is based on the work of the MinGW-w64 project (http://sourceforge.net/projects/mingw-w64/, but commercial compilers such as those from Intel and PGI could be used (and have been by R redistributors).

Support for MinGW-w64 was developed in the R sources over the period 2008–10 and was first released as part of R 2.11.0. The assistance of Yu Gong at a crucial step in porting R to MinGW-w64 is gratefully acknowledged, as well as help from Kai Tietz, the lead developer of the MinGW-w64 project.

Windows 64-bit is now completely integrated into the R and package build systems: a 64-bit build is selected in file MkRules.local.


Previous: , Up: Installing R under Windows   [Contents][Index]

3.2 Testing an Installation

The Windows installer contains a set of test files used when building R.

The Rtools are not needed to run these tests. but more comprehensive analysis of errors will be given if diff is in the path (and errorsAreFatal = FALSE is then not needed below).

Launch either Rgui or Rterm, preferably with --vanilla. Then run

Sys.setenv(LC_COLLATE = "C", LANGUAGE = "en")
library("tools")
testInstalledBasic("both")
testInstalledPackages(scope = "base", errorsAreFatal = FALSE)
testInstalledPackages(scope = "recommended", errorsAreFatal = FALSE)

runs the basic tests and then all the tests on the standard and recommended packages. These tests can be run from anywhere: they write some of their results in the tests folder of the R home directory (as given by R.home()), and hence may need to be run under the account used to install R.

The results of example(md5sums) when testing tools will differ from the reference output as some files are installed with Windows’ CRLF line endings.


Next: , Previous: , Up: Top   [Contents][Index]

4 Installing R under macOS

(‘macOS’ was known as ‘OS X’ from 2012–2016 and as ‘Mac OS X’ before that.)

The front page of a CRAN site has a link ‘Download R for OS X’. Click on that, then download the file R-3.5.0.pkg and install it. This runs on macOS 10.11 and later (El Capitan, Sierra, High Sierra, …).

Installers for R-patched and R-devel are usually available from https://r.research.att.com. (Some of these packages are unsigned: to install those Control/right/two-finger click, select ‘Open with’ and ‘Installer’.)

For some older versions of the OS you can in principle (it is little tested) install R from the sources (see macOS).

It is important that if you use a binary installer package that your OS is fully updated: look at ‘Updates’ from the ‘App Store’ to be sure. (If using XQuartz, check that is current.)

To install, just double-click on the icon of the file you downloaded. At the ‘Installation Type’ stage, note the option to ‘Customize’. This currently shows four components: everyone will need the ‘R Framework’ component: the remaining components are optional. (The ‘Tcl/Tk’ component is needed to use package tcltk. The ‘Texinfo’ component is only needed by those installing source packages or R from its sources.)

This is an Apple Installer package. If you encounter any problem during the installation, please check the Installer log by clicking on the “Window” menu and item “Installer Log”. The full output (select “Show All Log”) is useful for tracking down problems. Note the the installer is clever enough to try to upgrade the last-installed version of the application where you installed it (which may not be where you want this time …).

Various parts of the build require XQuartz to be installed: see https://xquartz.macosforge.org/. These include the tcltk package and the X11 device: attempting to use these without XQuartz will remind you. Also the cairographics-based devices (which are not often used on macOS) such as png(type = "cairo").

If you update your macOS version, you should re-install R (and perhaps XQuartz): the installer may tailor the installation to the current version of the OS.

For building R from source, see macOS.


Next: , Previous: , Up: Installing R under macOS   [Contents][Index]

4.1 Running R under macOS

There are two ways to run R on macOS from a CRAN binary distribution.

There is a GUI console normally installed with the R icon in /Applications which you can run by double-clicking (e.g. from Launchpad or Finder). (If you cannot find it there it was possibly installed elsewhere so try searching for it in Spotlight.) This is usually referred to as R.APP to distinguish it from command-line R: its user manual is currently part of the macOS FAQ at https://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html and can be viewed from R.APP’s ‘Help’ menu.

You can run command-line R and Rscript from a Terminal17 so these can be typed as commands like any other Unix-alike: see the next chapter of this manual. There are some small differences which may surprise users of R on other platforms, notably the default location of the personal library directory (under ~/Library/R, e.g. ~/Library/R/3.4/library), and that warnings, messages and other output to stderr are highlighted in bold.

It has been reported that running R.APP may fail if no preferences are stored, so if it fails when launched for the very first time, try it again (the first attempt will store some preferences).

Users of R.APP need to be aware of the ‘App Nap’ feature (https://developer.apple.com/library/mac/releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_9.html) which can cause R tasks to appear to run very slowly when not producing output in the console. Here are ways to avoid it:

Using the X11 device or the X11-based versions of View() and edit() for data frames and matrices (the latter are the default for command-line R but not R.APP) requires an X sub-system to be installed: see macOS. So do the tcltk package and some third-party packages.


Next: , Previous: , Up: Installing R under macOS   [Contents][Index]

4.2 Uninstalling under macOS

R for macOS consists of two parts: the GUI (R.APP) and the R framework. The un-installation is as simple as removing those folders (e.g. by dragging them onto the Trash). The typical installation will install the GUI into the /Applications/R.app folder and the R framework into the /Library/Frameworks/R.framework folder. The links to R and Rscript in /usr/local/bin should also be removed.

If you want to get rid of R more completely using a Terminal, simply run:

sudo rm -rf /Library/Frameworks/R.framework /Applications/R.app \
   /usr/local/bin/R /usr/local/bin/Rscript

The installation consists of up to four Apple packages:18 org.r-project.R.el-capitan.fw.pkg, org.r-project.R.el-capitan.GUI.pkg, org.r-project.x86_64.tcltk.x11 and org.r-project.x86_64.texinfo. You can use pkgutil --forget if you want the Apple Installer to forget about the package without deleting its files (useful for the R framework when installing multiple R versions in parallel), or after you have deleted the files.

Uninstalling the Tcl/Tk or Texinfo components (which are installed under /usr/local) is not as simple. You can list the files they installed in a Terminal by

pkgutil --files org.r-project.x86_64.tcltk.x11
pkgutil --files org.r-project.x86_64.texinfo

These are paths relative to /, the root of the file system.


Previous: , Up: Installing R under macOS   [Contents][Index]

4.3 Multiple versions

The installer will remove any previous version19 of the R framework which it finds installed. This can be avoided by using pkgutil --forget (see the previous section). However, note that different versions are installed under /Library/Frameworks/R.framework/Versions as 3.3, 3.4 and so on, so it is not possible to have different ‘3.x.y’ versions installed for the same ‘x’.

A version of R can be run directly from the command-line as e.g.

/Library/Frameworks/R.framework/Versions/3.4/Resources/bin/R

However, R.APP will always run the ‘current’ version, that is the last installed version. A small utility, Rswitch.app (available at https://r.research.att.com/#other), can be used to change the ‘current’ version. This is of limited use as R.APP is compiled against a particular version of R and will likely crash if switched to an earlier version. This may allow you nstall thosa development the conOne R: ib as yrks/R.framiffe, hs.d (see ttps://r.resthe GUI into the /Applicatious:

, Previous: , Up: Top   [Contents][Index, Previonstalling-R-under-macOS-1"><5 ccesskey="nstalrces/bi R sh>&rsqa partir the run directlike sectthatode>Rswitcdoesoolchainthe contents"./R="#tronOSX//a>vokus: vokus:y="n" and MkRules.loyour maeoid it:

rframewouo; veundR expp://reate (setions R.o on, so did complete256ter y amp>Mkpave rom A intallrnme oyour maparallelatform; veud completeas ldateand thesre lock uta: its uNetBSD you ins>R-d devicusere he run d_64.tclum; veility, tr collation, or set ="romanlelatforsamp> whicm typeftheir extercro HOME323.3 5.x pacR.hononot ofde>H)artz.maco failcuSethe defaTabfigd iable 5fPAPERSIZEonstalliner), cmnse requia and so onexcepamework.he envirPAPERSIZEg pkgutel="up">Topluding-ing o-tion">pludingting optionArticlsed asing optionssive anaalluchtml/small> wilME32

rhe envirPAPERSIZEg uo;Snlcury/R/3.4is talled,here isun verdevicuty indihothe lll> wilME32Open with&l cland ‘png, checkTEMP

The com/#oor MinGurnmrong> istime, s foump>winCalcuSe intne te consclassswitch //Apon, as is commions/R.apsamp>url&qing R under maRp> 5finclstallinge envR_inclLaunch eig> 5.x palsed asinthnd its unpaanfabsolutasinthnto rp>The W need quote(dquo;W onlyllerconsole. nts seche R aextercro nstall

Theferencquoof the piona the Ronton of R cwork/V/tm/Aaged binary butomihe defaTllampunch ejoblling R under maTMPDIR-3stallin do with it (utm png, the root ois MkRules.loge enviMPDIRe>pngBoth ehe defaTabfigd iable Mkpaseful for the R fallation b preferwork/V/tm/Apted in bomller /a> ssible to havenoo set ‘ge enviMPDIRe>png’ ( R cgraphi>Both mework. ier mp> should/ApplicAddp>

Multiple versions, Previ="#Running-R-under-macOS" accesskey=Installing R under mdows, Up: Top   [Contents][Index <6 Add-onists of uUnstalling R under maPts of uhninstaling R under ma> macOS.