This is a guide to installation and administration for R.
The current version of this document is 2.4.1 (2006-12-18).
ISBN 3-900051-09-7
Sources, binaries and documentation for R can be obtained via
CRAN, the “Comprehensive R Archive Network” whose current
members are listed at cran.r-project.org/mirrors.html.
The simplest way is to download the most recent R-x.y.z.tar.gz file, and unpack it with
tar xvfz R-x.y.z.tar.gz
on systems that have GNU tar installed. On other systems you need at least to have the gzip program installed. Then you can use
gzip -dc R-x.y.z.tar.gz | tar xvf -
The pathname of the directory into which the sources are unpacked should not contain spaces, as make (specifically GNU make 3.80) does not expect spaces.
If you need to transport the sources on floppy disks, you can download the R-x.y.z.tar.gz-split.* files and paste them together at the destination with (Unix)
cat R-x.y.z-split.* > R-x.y.z.tar.gz
and proceed as above. 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.)
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 (2.x.0) version, `r-patched' will refer to beta/release candidates of the upcoming release, the patched version of the current release being available only via Subversion.)
The tarballs are available from
ftp://ftp.stat.math.ethz.ch/pub/Software/R/. Download
either 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.
Sources are also available via https://svn.R-project.org/R/, the R
Subversion repository. If you have a Subversion client (see
subversion.tigris.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. 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 required, and that the SSL certificate for the Subversion server of the R project is
Certificate information:
- Hostname: svn.r-project.org
- Valid: from Jul 16 08:10:01 2004 GMT until Jul 14 08:10:01 2014 GMT
- Issuer: Department of Mathematics, ETH Zurich, Zurich, Switzerland, CH
- Fingerprint: c9:5d:eb:f9:f2:56:d1:04:ba:44:61:f8:64:6b:d9:33:3f:93:6e:ad
(currently, there is no “trusted certificate”). You can accept this certificate permanently and will not be asked about it anymore.
Note that retrieving the sources by e.g. wget -r or svn export from that URL will not work: 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 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 `http://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
wget -r -l1 --no-parent -A\*.gz -nd -P src/library/Recommended \
http://CRAN.R-project.org/src/contrib/dir
./tools/link-recommended
R will configure and build under a number of common Unix and Unix-alike platforms including `cpu-*-linux-gnu' for the `alpha', `arm', `hppa', `ix86', `ia64', `m68k', `mips', `mipsel', `powerpc', `s390', `sparc', and `x86_64' CPUs, `powerpc-apple-darwin', `i386-apple-darwin' and `sparc-sun-solaris', as well as probably (it is tested less frequently on these platforms) `i386-*-freebsd', `x86_64-*-freebsd', `i386-*-netbsd', `i386-*-openbsd', `i386-sun-solaris', `mips-sgi-irix' and `alpha-dec-osf*'.
In addition, binary distributions are available for some common Linux distributions and for Mac OS X. 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.
First review the essential and useful tools and libraries in Essential and useful other programs under Unix, 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 executed from) or points to a valid temporary directory.
Choose a place 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. (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'.)
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. To re-run the tests including those successfully run you would need
make check FORCE=FORCE
More comprehensive testing can be done by
make check-devel
or
make check-all
see tests/README.
If the command configure and make commands execute successfully, the R binary will be copied to R_HOME/bin/exec/R. In addition, a shell-script front-end called R will be created and copied to the same directory. You can 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 the pathname of the build directory should not contain spaces.)
Make will also build plain text help pages as well as HTML and
LaTeX versions of the R object documentation (the three kinds can
also be generated separately using make help, make html
and make latex). Note that you need Perl version 5: if this is
not available on your system, you can obtain PDF versions of the
documentation files via CRAN.
For those obtaining R via Subversion, one additional step is necessary:
make vignettes
which makes the grid vignettes (which are contained in the tarballs): it takes several minutes.
Now rehash if necessary, type R, and read the R manuals
and the R FAQ (files FAQ or
doc/manual/R-FAQ.html, or
CRAN.R-project.org/doc/FAQ/R-FAQ.html which always has
the latest version).
There is a set of manuals that can be built from the sources,
To make these, use
make dvi to create DVI versions make pdf to create PDF versions make info to create info files (not `refman').
You will not be able to build the info files unless you have makeinfo version 4.7 or later installed.
The DVI versions can be previewed and printed using standard programs such as xdvi and dvips. The PDF versions can be viewed using Acrobat Reader or (fairly recent versions of) xpdf and ghostscript: they have hyperlinks that can be followed in the first two. The info files are suitable for reading online with Emacs or the standalone GNU Info. The DVI and PDF versions will be created using the papersize 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 papersize, you should first delete the file doc/manual/version.texi.)
There are some issues with making the reference manual, and in particular with the PDF version 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:
timeslmwww.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-superwww.ctan.org/tex-archive/fonts/ps-type1/cm-super
and its mirrors. These type-1 fonts have poor hinting and so are
nowhere near so readable on-screen as the other three options.
aeThe default can be overridden by setting the environment variable
R_RD4PDF. (On Unix, this will be picked up at install time.) The
default value is times,hyper: omit hyper if you do not
want hyperlinks, e.g. for printing.
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
This will install to the following directories:
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
This causes make install to install the R executable 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. You can install into another directory tree by using
make prefix=/path/to/here install
at least with GNU make.
More precise control is available at configure time via options: see configure --help for details. (However, many of them are currently unused.)
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.
All of bindir and mandir and libdir can also be
specified on the make install command line.
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-2.4.1.
If you have made R as a shared/dynamic 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.
To install DVI, info and PDF versions of the manuals, use one or more of
make install-dvi
make install-info
make install-pdf
Once again, it is optional to specify prefix.
More precise control is possible. For info, the setting used is that of
infodir (default `prefix/info', set by configure
option --infodir). The DVI and PDF files are installed into
the R doc tree, set by the make variable
rdocdir.
You can uninstall R by
make uninstall
specifying prefix etc in the same way as specified for
installation.
This will also uninstall any installed manuals. There are specific targets to uninstall DVI, info and PDF manuals in doc/manual/Makefile.
Some platforms can support closely related builds of R which can share all but the executables and dynamic objects. Examples include builds under Solaris for different chips (in particular, 32- and 64-bit builds), 64- and 32- bit builds on `x86_64' Linux and different CPUs (`ppc', `ppc64' and `i386') under MacOS 10.4.
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 libs. Example
names from other systems are the use of sparcv9 on 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 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 63Mb, 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 that 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 `pkg(s)'
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 Windows 95, 98, NT4, 2000, ME, XP and 2003 (at least) on Intel x86 and clones (including AMD64/EM64T chips and Windows 64).
Your file system must allow long file names (as is likely except perhaps for some network-mounted systems).
Installation is via the installer R-2.4.1.exe. Just double-click on the icon and follow the instructions. You can uninstall R from the Control Panel. (Note that you will probably (depending on the Windows language settings) 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.
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
www.murdoch-sutherland.com/Rtools) for details.
Be sure to set your path in the order given in the appendix.
You need to collect the following sets of files:
tar zxvf R-2.4.1.tar.gz
to create the source tree in R_HOME. Beware: do use tar to extract the sources rather than tools such as WinZip that do not understand about symbolic links.
It is also possible to obtain the source code using Subversion; see Obtaining R for details.
www.murdoch-sutherland.com/Rtools/iconv.zip and put it in
R_HOME/src/gnuwin32/unicode.
www.murdoch-sutherland.com/Rtools/R_Tcl.zip: unzip this in
R_HOME, and it will add directories R_HOME/Tcl,
R_HOME/Tcl/bin, etc.
libpng and jpeg sources (available, e.g., from
www.libpng.org,
ftp://ftp.uu.net/graphics/[png,jpeg]. You will need files
libpng-1.2.8.tar.gz and jpegsrc.v6b.tar.gz or later.
make
link-recommended. If you have rsync and an Internet
connection, you can do this automatically using
make rsync-recommended
math-atlas.sourceforge.net) tuned to your system for fast linear
algebra routines. Pre-built Rblas.dll for various Pentium and
AthlonXP chips are available in the windows/contrib/ATLAS area on
CRAN. If you are building R from source, there are macros
USE_ATLAS and ATLAS_PATH in the file MkRules. Set
USE_ATLAS = YES and ATLAS_PATH to where the ATLAS
libraries are located. You will need to make the libraries
yourself1: none of the binaries we have seen are compiled for
the correct compiler. Since R has its own `xerbla' it is best
to delete that in ATLAS by
ar d /path/to/libf77blas.a xerbla.o
Another possibility is to use AMD's AMD Core Math Library (ACML)
www.amd.com/acml. To use the
Cygwin-compiled version (Cygwin itself is not needed, at least
currently), install acml-3-5-0-win32-g77.exe (or later) and edit
R_HOME/src/gnuwin32/MkRules to define
USE_ACML=YES and set ACML_PATH to the path to
libacml.a. If you also set USE_ACML_LAPACK=YES, ACML will
be used to provide the LAPACK library for R itself and any packages
using LAPACK_LIBS built under that setting.
There used to be support for Kazushige Goto's BLAS, but this is no longer available in binary form for Windows, and it seems that it will in future only to be offered via a source-code licence.
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. Edit MkRules to set the appropriate paths as needed and to set the type(s) of help that you want built. Beware: MkRules contains tabs and some editors (e.g., WinEdt) silently remove them. Then run
make all recommended
and sit back and wait while the basic compile takes place.
Notes:
malloc in the file
R_HOME/src/gnuwin32/malloc.c is used for R's internal memory
allocations. You can opt out of this by commenting the line
LEA_MALLOC=YES in MkRules, in which case the
malloc in msvcrt.dll is used. This does work but
imposes a considerable performance penalty.
make -j2 all
make recommended
but this is only likely to be worthwhile on a dual-processor/dual-core machine with ample (at least 384Mb) of memory. (On a dual AthlonMP it reduced the build time by about 30%.) Note that this may sometimes stop and have to be restarted.
The file R_HOME/bin/Rbitmap.dll is not built automatically.
Working in the directory R_HOME/src/gnuwin32/bitmap,
install the libpng and jpeg sources in sub-directories.
The libpng sub-directory must be named libpng (as required
by the libpng documentation). The jpeg sub-directory for
version 6b is named jpeg-6b; if you use a different version, edit
Makefile and change the definition of JPEGDIR.
Example:
> tar xzvf libpng-1.2.8.tar.gz
> mv libpng-1.2.8 libpng
> tar xzvf jpegsrc.v6b.tar.gz
Once everything is set up in directory bitmap, make
in that directory or make bitmapdll in the parent directory
should build Rbitmap.dll and install it in R_HOME/bin.
You can test a build by running make check. You may need to set
TMPDIR to the absolute path to a suitable temporary directory: the
default is `c:/TEMP'. (Use forward slashes and do not use a path
including spaces.)
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 check-devel and check-recommended.
The PDF manuals can be made by
make manuals
If you want to make the info versions (not the Reference Manual), use
cd ../../doc/manual
make -f Makefile.win info
To make DVI versions of the manuals use
cd ../../doc/manual
make -f Makefile.win dvi
(all assuming you have tex and latex installed and in your path).
See the Making the manuals section in the Unix section for setting options such as the paper size.
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 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 installers and put them in the gnuwin32/cran subdirectory, then check the build. This works by building all the parts in the sequence:
Rpwd.exe (a utility needed in the build) rbuild (the executables, the FAQ docs etc.) rpackage (the base packages) htmldocs (the HTML documentation) bitmapdll (the bitmap support files) recommended (the recommended packages) vignettes (the vignettes in package grid: only needed if building from svn checkout) manuals (the PDF manuals) rinstaller (the install program) crandir (the CRAN distribution directory)
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' is run.
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 a full installation of R from the standard installer (that is, select `Full Installation' from the `Select Components' screen), then add packages and make other customizations to that installation. Then in src/gnuwin32/installer run
make myR IMAGEDIR=rootdir
where rootdir is the path to the root of the customized installation (forward slashes and no spaces, please). This creates an executable with the standard name, R-2.4.1.exe, so please rename it to indicate that it is customized.
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.
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 available from http://wix.sourceforge.net/: we tested version 2.0. (This needs the .NET 1.1 framework installed: it ran on a vanilla Windows XP SP2 machine. Probably Windows 2000 or later is required by some of the features used.) Once WiX is installed, set the path to its home directory in MkRules.
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. Then
cd installer
make msi
which will results in a file of about 40Mb with a name like R-2.4.0-win32.msi. This can be double-clicked to be installed, but those who need it will know what to do with it.
Thanks to David del Campo (Dept of Statistics, University of Oxford) for suggesting WiX and building a prototype installer.
It is possible to cross-build R or packages on (at least) `ix86' and `x86_64' Linux, and the `ix86' cross-compilers have also been used successfully on `x86_64' Linux..
You will need suitable cross-compilers installed and in your path.
There is currently a complete set of tools at
www.stats.ox.ac.uk/pub/Rtools/mingw-cross5.tar.bz2 (Just
unpack this somewhere and put its bin directory in your path.)
It is also straightforward to build a set of cross-compilers via the
scripts available at
http://sourceforge.net/forum/forum.php?forum_id=632611.
You will need Perl, zip and unzip installed and
makeinfo version 4.7 or later (part of GNU texinfo).
You also need the R source (R-2.4.1.tar.gz).
Then: untar R-2.4.1.tar.gz somewhere, and
cd /somewhere/R-2.4.1/src/gnuwin32
Edit MkRules to set BUILD=CROSS and the appropriate
paths (including HEADER) as needed.
Edit MkRules to set the type(s) of help that you want built. (You
will not be able to cross-build .chm files, so WINHELP is
automatically set to NO.)
You also need a working copy of this version of R on Linux:
uncomment and set R_EXE in MkRules to point to it.
Then run make (and parallel make works reliably, unlike on Windows).
Packages can be made in the same way as natively: see Customizing package compilation under Windows, via the Makefiles but not via `R CMD INSTALL'. So care is needed where packages have dependencies: Linux versions of the dependencies must be installed in a library in the search path. So for example to cross-build the MCMCpack package we used
# MCMCpack depends on coda, so point to the library containing it
export R_LIBS=/R/library
make PKGDIR=/mysources pkg-MCMCpack
make PKGDIR=/mysources lazyload-MCMCpack
cd ../../library
zip -r9X /dest/MCMCpack_0.7-4.zip MCMCpack
Even so, packages which depend on others that need to run compiled code to load may not work (methods is a special exception).
To distribute a cross-build (or just to transfer it to a Windows machine for testing) use
cd installer
make imagedir
zip -r9X R-2.4.1.zip R-2.4.1 # or something similar
We have not found a reliable way to convert base to lazy-loading when cross-building, so it is left in the old format. Note too that .chm help files (the default for a vanilla binary installation) will not be made when cross-building.
Also based on this facility is Makefile-rcb by J. Yan and A. J. Rossini. For details, see the Makefile itself, or http://cran.r-project.org/doc/contrib/cross-build.pdf.
The bin/macosx directory of a CRAN site contains binaries for MacOS X for a base distribution and a large number of add-on packages from CRAN to run on Mac OS X version 10.4.4 or higher.
The simplest way is to use R-2.4.1.dmg. Just double-click on the icon and the disk image file will be mounted. Read the ReadMe.txt inside the disk image and follow the instructions.
See the R for Mac OS X FAQ for more details.
If you want to build this port from the sources, you can read the above mentioned R for Mac OS X FAQ for full details. You will need to collect and install some tools as explained in the document. Than you have to expand the R sources and configure R appropriately, for example
tar zxvf R-2.4.1.tar.gz
cd R-2.4.1
./configure --with-blas='-framework vecLib' --with-lapack \
--with-aqua --enable-R-framework
make
and then sit back and wait. The first two options are the default (and
strongly recommended), and with some toolsets have been essential. The
second line of options is also default on Mac OS X, but needed only if
you want to build R for use with R.app Console, and imply
--enable-R-shlib to build R as a shared/dynamic library.
These options configure R to be built and installed as a framework called R.framework. The default path for R.framework is /Library/Frameworks but this can be changed at configure time specifying the flag --enable-R-framework[=DIR] or at install time as
make prefix=/where/you/want/R.framework/to/go install
the R.framework has not to be specified in the path.
How to start R and what command-line options are available is discussed in Invoking R.
R makes use of a number of environment variables, the default values of many of which are set in file R_HOME/etc/Renviron (there are none set by default on Windows and hence no such file). These are set at configure time, and you would not normally want to change them – a possible exception is R_PAPERSIZE (see Setting paper size). As from R 2.4.0 the paper size will be deduced from the `LC_PAPER' locale category if it exists and R_PAPERSIZE is unset, and this will normally produce the right choice from `a4' and `letter' on modern Unix-alikes (but can always be overridden by setting R_PAPERSIZE).
Various environment variables can be set to determine where R creates its per-session temporary directory. The environment variables TMPDIR, TMP and TEMP are searched in turn and the first one which is set and points to a writable area is used. If none do, the final default is /tmp on Unix-alikes and the value of R_USER on Windows.
Some Unix-alike systems are set up to remove files and directories periodically from /tmp, for example by a cron job running tmpwatch. Set TMPDIR to another directory before running long-running jobs on such a system.
Note that TMPDIR will be used to execute configure
scripts when installing packages, so if /tmp has been mounted as
`noexec', TMPDIR needs to be set to a directory from which
execution is allowed.
It is helpful to use the correct terminology. A package is
loaded from a library by the function library(). Thus a
library is a directory containing installed packages; the main library
is R_HOME/library, but others can be used, for example by
setting the environment variable R_LIBS or using the R function
.libPaths().
Packages may be distributed in source form or compiled binary form. Installing source packages requires that compilers and tools (including Perl 5.004 or later) be installed. Binary packages are platform specific and generally need no special tools to install, but see the documentation for your platform for details.
Note that you need to specify implicitly or explicitly the library to which the package is to be installed. This is only an issue if you have more than one library, of course.
To install packages from source in Unix use
R CMD INSTALL -l /path/to/library pkg1 pkg2 ...
The part `-l /path/to/library' can be omitted, in which case the first library in R_LIBS is used if set, otherwise the main library R_HOME/library is used. (R_LIBS is looked for in the environment: note that .Renviron is not read by R CMD.) Ensure that the environment variable TMPDIR is either unset (and /tmp exists and can be written in and executed from) or points to a valid temporary directory.
There are a number of options available: use R CMD INSTALL --help
to see the current list.
The same command works in Windows if you have the source-code package files (option “Source Package Installation Files” in the installer) and toolset (see The Windows toolset) installed.
Alternatively, packages can be downloaded and installed from within
R. First set the option CRAN to your nearest CRAN
mirror using chooseCRANmirror(). Then download
and install packages pkg1 and pkg2 by
> install.packages(c("pkg1", "pkg2"))
Unless the library is specified (argument lib) the first library
in the library search path is used. If you want to fetch a package and
all those it depends on that are not already installed, use e.g.
> install.packages("Rcmdr", dependencies = TRUE)
What install.packages does by default is different on Unix and
Windows. On Unix-alikes (include MacOS X unless running from the GUI
console) it consults the list of available source packages on
CRAN (or other repository/ies), downloads the latest version
of the package sources, and installs them (via R CMD INSTALL).
On Windows it looks (by default) at the list of binary versions
of packages available for your version of R and downloads the latest
versions (if any), although optionally it will also download and install
a source package by setting the type argument.
install.packages can install a source package from a local
.tar.gz file by setting argument repos to NULL.
On Windows install.packages can also install a binary package
from a local zip file by setting argument repos to
NULL. Rgui.exe has a menu Packages with a GUI
interface to install.packages, update.packages and
library.
install.packages can look in several repositories, specified as a
character vector by the argument repos: these can include a
CRAN mirror, Bioconductor, Omegahat, local archives, local
files, ...).
On Mac OS X install.packages works as it does on other Unix-like
systems, but there is an additional type mac.binary that can be
passed to install.package in order to download and install binary
packages from CRAN. These Macintosh binary package files have
the extension `tgz'. The R GUI provides for installation of either
binary or source packages, from CRAN or local files.
The R system and package-specific compilation flags can be overridden or
added to by setting the appropriate Make variables in the personal file
$HOME/.R/Makevars-$R_PLATFORM, or if that does not exist,
$HOME/.R/Makevars, where `R_PLATFORM' is the platform for
which R was built, as available in the platform component of the
R variable R.version.
Package developers are encouraged to use this mechanism to enable a reasonable amount of diagnostic messaging (“warnings”) when compiling, such as e.g. -Wall -pedantic for tools from GCC, the Gnu Compiler Collection.
This section describes ways to customize package compilation using the standard C, C++ and FORTRAN compilers and tools. For instructions on using non-standard tools, see the README.packages file.
The Makefiles can be customized: in particular the name of the DLL can
be set (for example we once needed integrate-DLLNM=adapt), the
compile flags can be set (see the examples in MakeDll) and the
types of help (if any) to be generated can be chosen (variables
HELP, HELPTYPES and WINHELP). The simplest way to
customize the compilation steps is to set variables in a file
src/Makevars.win, which will automatically be included by
MakeDLL. For example, for RODBC src/Makevars.win could
include the line
DLLLIBS+=-lodbc32
or, equivalently,
RODBC-DLLLIBS=-lodbc32
but in fact contains the single line
PKG_LIBS=-lodbc32
If you have a file src/Makefile.win, that will be used as the makefile for source compilation in place of our makefile and MakeDll and src/Makevars.win will be ignored.
Package-specific compilation flags can be overridden or added to using
the personal file $HOME/.R/Makevars.win, or if that does not
exist, $HOME/.R/Makevars. (See the rw-FAQ for the meaning
of $HOME.) For the record, the order of precedence is (last wins)
Beware: files src/Makefile or src/Makevars will be used if they exist and the .win equivalents do not. Such files included in package sources are usually designed for use under Unix and are best removed.
Beware: references to variables in R.dll are converted to the right form by using the header files. You must include them.
For additional control, R_HOME/src/gnuwin32/Makefile
contains additional make targets corresponding to various options to
R CMD INSTALL. These assume that package foo's source
code has been installed in directory
R_HOME/src/library/foo. Then make pkg-foo is similar
to R CMD INSTALL foo (but the latter would require
R_HOME/src/library to be the current directory). Other
targets are
ziponly-foo, to use zip to compress the help files after building
the package.
ziphelp-foo to both compress the help files and to keep the
originals.
zipdata-foo to compress the data files. This is recommended if
you have either many small data files (as in package Devore5) or a
few large data files.
pkgcheck-foo to check the package (like R CMD check foo).
Using this approach allows variables to be set during the build, e.g.
make PKGDIR=/mysources RLIB=/R/library pkg-foo
Some variables that may be used include:
DEBUG=T to compile with debugging information for gdb.
PKG_CFLAGS= to specify options to the C compiler.
PKG_CPPFLAGS= to specify options to the preprocessor.
PKG_CXXFLAGS= to specify options to the C++ compiler.
PKG_FFLAGS= to specify options to the FORTRAN 77 compiler.
PKG_FCFLAGS= to specify options to the Fortran 95 compiler (if
specified).
PKG_LIBS= to specify options to the linking step making the DLL.
PKGDIR=/path/to/source to specify the path to the package source files.
RLIB=/path/to/library to specify the path to the library
where the package should be installed.
PKG_* flags are those
typically included in Makevars files.
The command update.packages() is the simplest way to ensure that
all the packages on your system are up to date. Set the repos
argument as in the previous section. The update.packages()
downloads the list of available packages and their current versions,
compares it with those installed and offers to fetch and install any
that have later versions on the repositories.
An alternative interface to keeping packages up-to-date is provided by
the command packageStatus(), which returns an object with
information on all installed packages and packages available at multiple
repositories. The print and summary methods give an
overview of installed and available packages, the upgrade method
offers to fetch and install the latest versions of outdated packages.
Packages can be removed in a number of ways. From a command prompt they can be removed by
R CMD REMOVE -l /path/to/library pkg1 pkg2 ...
From a running R process they can be removed by
> remove.packages(c("pkg1", "pkg2"),
lib = file.path("path", "to", "library"))
Finally, in most installations one can just remove the package directory from the library.
Note: only remove.packages can remove package
bundles.
Utilities such as install.packages can be pointed at any
CRAN-style repository, and R users may want to set up their own. The
`base' of a repository is a URL such as
http://www.omegahat.org/R: this must be an URL scheme that
download.packages supports (which also includes `ftp://' and
`file://'). Under that base URL there should be directory trees
for one or more of the following types of package distributions:
"source": located at src/contrib and containing
.tar.gz files.
"win.binary": located at bin/windows/contrib/x.y for
R versions x.y.z and containing .zip files.
"mac.binary": located at
bin/macosx/powerpc/contrib/x.y or
bin/macosx/i686/contrib/x.y for R versions x.y.z
and containing .tgz files.
Each terminal directory must also contain a PACKAGES file. This
can be a concatenation of the DESCRIPTION files of the packages
separated by blank lines (provided there are no bundles), but only a few
of the fields are needed. The simplest way to set up such a file is to
use function write_PACKAGES in the tools package, and its
help explains which fields are needed. Optionally there can also be
a PACKAGES.gz file, a gzip-compressed version of
PACKAGES.
To add your repository to the list offered by setRepositories(),
see the help file for that function.
Internationalization refers to the process of enabling support for non-English languages, and localization to adapting to a specific country and language.
R has long worked in the ISO Latin-1 8-bit character set and so
covered English and most Western European languages (if not necessarily
their currency symbols). What characters are valid in names was taken
from the current locale. In general other locales with single-byte
encodings worked, but e.g. postscript() and pdf() needed
to be told about the encoding in use.
Full internationalization can be enabled when R is built under Unix-alikes by the (default) configure option --enable-mbcs: see Configuration on Unix. Under Windows, it is enabled by default in source builds, but support for `East Asian' (Chinese/Japanese/Korean) languages is only enabled in the binary install if it is selected in the installer.
All builds of R support all single-byte character sets that the
underlying OS can handle. These are interpreted according to the
current locale, a sufficiently complicated topic to merit a
separate section. Fully internationalized builds can also handle most
multi-byte locales, in which a single character is represented by one,
two or more consecutive bytes: examples of such locales are those using
UTF-8 (becoming standard under Linux) and those for Chinese, Japanese
and Korean. Note that only some of the graphics devices can handle
multi-byte or even non-Latin-1 character sets.
The other aspect of the internationalization is support of the translation of messages. This is enabled in almost all builds of R.
A locale is a description of the local environment of the user,
including the preferred language, the encoding of characters, the
currency used and its conventions, and so on. Aspects of the locale are
accessed by the R functions Sys.getlocale and
Sys.localeconv.
The system of naming locales is OS-specific. There is quite wide agreement on schemes, but not on the details of their implementation. A locale needs to specify
R is principally concerned with the first (for translations) and third. Note that the charset may be deducible from the language, as some OSes offer only one charset per language, and most OSes have only one charset each for many languages. Note too the remark above about Chinese.
Modern Linux uses the XPG locale specifications which have the form `en_GB', `en_GB.utf8', `aa_ER.utf8@saaho', `de_AT.iso885915@euro', the components being in the order listed above. (See man locale and locale -a for more details.) Similar schemes (but often in different cases) are used by most Unix-alikes.
Windows also uses locales, but specified in a rather less concise way.
Most users will encounter locales only via drop-down menus, but more
information and lists can be found at
msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_language_and_country_strings.asp.
Mac OS X supports locales in its own particular way, but the R GUI tries
to make this easier for users. See
developer.apple.com/documentation/MacOSX/Conceptual/BPInternational/
for how users can set their locales. As with Windows, end users will generally only see lists of languages/territories.
Internally Mac OS X uses a form similar to Linux but without specifying
the encoding (which is UTF-8).
The preferred language for messages is by default taken from the locale. This can be overridden first by the setting of the environment variable LANGUAGE and then by the environment variables LC_ALL, LC_MESSAGES and LANG. (The last three are normally used to set the locale and so should not be needed, but the first is only used to select the language for messages.) The code tries hard to map locales to languages, but on some systems (notably Windows) the locale names needed for the environment variable LC_ALL do not all correspond to XPG language names and so LANGUAGE may need to be set. (One example is `LC_ALL=es' on Windows which sets the locale to Estonian and the language to Spanish.)
It is usually possible (not Windows) to change the language once R is
running via Sys.setlocale("LC_MESSAGES", "new_locale"),
but not by setting environment variables such as LANGUAGE.
Messages are divided into domains, and translations may be available for some or all messages in a domain. R makes use of the following domains.
R for basic C-level error messages.
R-pkg for the R stop, warning and
message messages in each package, including R-base for the
base package.
RGui for the menus etc of the R for Windows GUI front-end.
Dividing up the messages in this way allows R to be extensible: as packages are loaded, their message translation catalogues can be loaded too.
Translations are looked for by domain according to the currently specified language, as specifically as possible, so for example an Austrian (`de_AT') translation catalogue will be used in preference to a generic German one (`de') for an Austrian user. However, if a specific translation catalogue exists but does not contain a translation, the less specific catalogues are consulted. For example, R has catalogues for `en_GB' that translate the Americanisms (e.g., `gray') in the standard messages into English. Two other examples: there are catalogues for `es', which is Spanish as written in Spain and these will by default also be used in Spanish-speaking Latin American countries, and also for `pt_BR', which are used for Brazlian locales but not for locales specifying Portugal.
Translations in the right language but the wrong charset be made use of by on-the-fly re-encoding (on systems that support it). The LANGUAGE variable (only) can be a colon-separated list, for example `se:de', giving a set of languages in decreasing order of preference. One special value is `en@quot', which can be used in a UTF-8 locale to have English/American error messages with pairs of quotes translated to Unicode directional quotes.
If no suitable translation catalogue is found or a particular message is not translated in any suitable catalogue, English is used.
See developer.r-project.org/Translations.html for how to prepare
and install translation catalogues.
Many current CPUs have both 32- and 64-bit sets of instructions: this has long been true for UltraSparc and more recently for MIPS, PPC and `x86_64' (AMD Opteron and Athlon64, Intel Xeon and Pentium/'Core' supporting EM64T). Many OSes running on such CPUs offer the choice of building a 32-bit or a 64-bit version of R (and details are given below under specific OSes). For most a 32-bit version is the default, but for some (e.g., `x86_64') 64-bit is.
All current versions of R use 32-bit integers and IEC 605592 double-precision reals, and so compute to the same precision3 and with the same limits on the sizes of numerical quantities. The principal difference is in the size of the pointers.
64-bit builds have both advantages and disadvantages:
R allocates memory for large objects as needed, and removes any unused ones at garbage collection. When the sizes of objects become an appreciable fraction of the address limit, fragmentation of the address space becomes an issue and there may be no hole available that is the size requested. This can cause more frequent garbage collection or the inability to allocate large objects. As a guide, this will become an issue with objects more than 10% of the size of the address space (around 300Mb) or when the total size of objects in use is around one third (around 1Gb).
So, for speed you may want to use a 32-bit build, but to handle large datasets (and perhaps large files) a 64-bit build. You can build both and install them in the same place: See Sub-architectures.
Even on 64-bit builds of R there are limits on the size of R
objects (see help("Memory-limits"), some of which stem from the
use of 32-bit integers (especially in FORTRAN code). On all versions of
R, the maximum length (number of elements) of a vector is
2^31-1, about 2 billion, and on 64-bit systems the size of a
block of memory allocated is limited to 2^34-1 bytes (8GB). It
is anticipated these will be raised eventually but routine use of 8GB
objects is (in 2005) several years off.
Currently the Windows build of R is a 32-bit executable. This runs happily on Windows 64 on AMD64 and EM64T, but is limited to (we are told) a 2GB address space. It will not be possible to provide a native version for Windows 64 until suitable compilers are available, and currently (mid-2006) that is not in prospect.5
This appendix gives details of programs you will need to build R on Unix-like platforms, or which will be used by R if found by configure.
Remember that some package management systems (such as RPM and deb) make a distinction between the user version of a package and the development version. The latter usually has the same name but with the extension `-devel' or `-dev': you need both versions installed.
You need a means of compiling C and FORTRAN 77 (see Using FORTRAN). Some add-on packages also need a C++ compiler. Your C
compiler should be IEC 600596, POSIX 1003.1 and C99-compliant if at all
possible. R tries to choose suitable flags for the C compilers it
knows about, but you may have to set CC or CFLAGS suitably.
For recent versions of gcc with glibc this means including
-std=gnu99 (-std=c99 excludes POSIX functionality).
If the compiler is detected as gcc, -std=gnu99 will be
appended to CC unless it conflicts with a setting of CFLAGS.
Unless you do not want to view graphs on-screen you need `X11' installed, including its headers and client libraries. (On Fedora Core 3 and SuSE 9.x Linux this meant the `xorg-x11-devel' and `xorg-x11-libs' RPMs. On Fedora Core 5 and 6 it means (at least) `libX11', `libX11-devel', `libXt' and `libXt-devel'. On Debian we recommend the meta-package `xorg-dev'.) If you really do not want these you will need to explicitly configure R without X11, using --with-x=no.
The command-line editing depends on the readline library
available from any GNU mirror: you will need a fairly recent
version. Otherwise you will need to configure with
--with-readline=no (or equivalent).
You will need Perl version 5.004 or later, available via
www.perl.com/CPAN, to build any
of the on-line documentation.
You will not be able to build the info files unless you have makeinfo version 4.7 or later installed, and if not some of the HTML manuals will be linked to CRAN. (Version 4.6 is known to create incorrect HTML files.)
The typeset documentation and building vignettes needs tex and latex, or pdftex and pdflatex.
If you want to build from the R Subversion repository you need Perl, makeinfo and pdflatex.
The use of multi-byte characters, conversion between encodings
(including for translated messages) and the R iconv function
depend on having the system iconv function: this is part of
recent versions of glibc and many Unixes. You can also install
GNU libiconv (which is not the same as that in
glibc), possibly as a plug-in replacement: see
www.gnu.org/software/libiconv. Note that the R usage
requires iconv to be able to translate between "latin1"
and "UTF-8", to recognize "" as the current encoding and
to translate to and from the Unicode wide-character formats
"UCS-[24][BL]E" – this is not true of most commercial Unixes.
The ability to use translated messages makes use of gettext and
most likely needs GNU gettext: you do need this to work
with new translations, but otherwise the version contained in the R
sources will be used if no suitable external gettext is found.
The bitmapped graphics devices jpeg() and png() need the
appropriate headers and libraries installed: jpeg (version 6b or
later) or libpng (version 1.2.3 or later) and zlib
(version 1.1.3 or later) respectively.
The bitmap and dev2bitmap devices and also
embedFonts() use ghostscript (www.cs.wisc.edu/~ghost).
If you have them installed (including the appropriate headers and of
recent enough versions), zlib, libbz2 and PCRE will be
used if specified by --with-system-zlib,
--with-system-bzlib or --with-system-pcre: otherwise
versions in the R sources will be compiled in. As the latter suffice
and are tested with R you should not need to change this. In
particular, the version of zlib 1.2.3 in the R sources has
enhancements to work with large file systems on 32-bit platforms.
The tcltk package needs Tcl/Tk installed: the sources are
available at www.tcl.tk. To specify
the locations of the Tcl/Tk files you may need the configuration options
or use the configure variables TCLTK_LIBS and
TCLTK_CPPFLAGS to specify the flags needed for linking against
the Tcl and Tk libraries and for finding the tcl.h and
tk.h headers, respectively. If you have both 32- and 64-bit
versions of Tcl/Tk installed, setting the paths to the correct config
files will most likely be necessary to avoid confusion between them.
Versions of Tcl/Tk from 8.3 to 8.4.13 have been used successfully: 8.0 is no longer supported.
configure looks for Java support on the host system, and if it finds it sets some settings which are useful for Java-using packages. JAVA_HOME can be set during the configure run to point to a specific JRE/JDK.
Principal amongst these are some library paths to the Java libraries and JVM, which are stored in environment variable R_JAVA_LD_LIBRARY_PATH in file R_HOME/etc/ldpaths (or a sub-architecture-specific version). A typical setting for Sun Java is
/usr/java/jdk1.5.0_06/jre/lib/amd64/server:/usr/java/jdk1.5.0_06/jre/lib/amd64
Note that this unfortunately depends on the exact version of the JRE/JDK installed, and so will need updating if the Java installation is updated. This can be done either by editing that file or setting R_JAVA_LD_LIBRARY_PATH (e.g. in ~/.Renviron), or using /etc/ld.so.conf to specify the Java runtime library paths to the system.
Other settings are recorded in etc/Makeconf (or a sub-architecture-specific version), e.g.
JAVA = /usr/bin/java
JAVAC = /usr/bin/javac
JAVA_HOME = /usr/java/jdk1.5.0_06/jre
JAVA_LD_LIBRARY_PATH = $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:\
$(JAVA_HOME)/../lib/amd64:/usr/local/lib64
JAVA_LIBS = -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64
-L$(JAVA_HOME)/../lib/amd64 -L/usr/local/lib64 -ljvm
where `JAVA_LIBS' contains flags necessary to link JNI programs.
The linear algebra routines in R can make use of enhanced BLAS (Basic
Linear Algebra Subprograms, www.netlib.org/blas/faq.html) routines. However, as from R
2.4.07 these have to be explicitly
requested at configure time: R provides an internal BLAS which is
well-tested and will be adequate for most uses of R.
You can specify a particular BLAS library via a value for the
configuration option --with-blas and not to use an external
BLAS library by --without-blas (the default). If
--with-blas is given with no, its value is taken from the
environment variable BLAS_LIBS, set for example in
config.site. If neither the option nor the environment variable
supply a value, a search is made for a suitable BLAS. If the value is
not obviously a linker command (starting with a dash or giving the path
to a library), it is prefixed by -l, so
--with-blas="foo"
is an instruction to link against -lfoo to find an external BLAS
(which needs to be found both at link time and run time).
The configure code checks that the external BLAS is complete (it must
include all 8 double
precision and double complex routines9, as well as LSAME), and
appears to be usable. However, an external BLAS has to be usable from a
shared object (so must contain position-independent code), and that is
not checked.
Some enhanced BLASes are compiler-system-specific (libsunperf on
Sun Sparc10, libessl on IBM, vecLib on
Mac OS X). The correct incantation for these is usually found
via --with-blas with no value on the appropriate
platforms.
Some of the external BLASes are multi-threaded. One issue is that R
profiling (which uses the SIGPROF signal) may cause problems, and
you may want to disable profiling if you use a multi-threaded BLAS.
Note that using a multi-threaded BLAS can result in taking more CPU time
and even more elapsed time (occasionally dramatically so) than using a
similar single-threaded BLAS.
Note that under Unix (but not under Windows) if R is compiled against a non-default BLAS and --enable-BLAS-shlib is not used, then all BLAS-using packages must also be. So if R is re-built to use an enhanced BLAS then packages such as quantreg will need to be re-installed.
ATLAS (math-atlas.sourceforge.net) is a “tuned” BLAS that runs on a
wide range of Unix-alike platforms. If no more specific library is
found, a libblas library in the library path will be used. (The
later may not be an enhanced BLAS and so may be less desirable than the
internal BLAS.)
The usual way to specify ATLAS will be via
--with-blas="-lf77blas -latlas"
if the libraries are in the library path, otherwise by
--with-blas="-L/path/to/ATLAS/libs -lf77blas -latlas"
For systems with multiple processors it is possible to use a multi-threaded version of ATLAS, by specifying
--with-blas="-lptf77blas -lpthread -latlas"
Users of Fedora Core 4 Extras may want to use
--with-blas="-lf77blas -latlas -llapack_atlas" --with-lapack
since the basic BLAS on that system is incomplete.
The BLAS library must be usable with dynamically-loadable code: this can be a problem with ATLAS on some platforms (including Linux on `x86_64') as it is not by default built with position-independent code.
An ATLAS `tuned' BLAS can also be used on Windows: see see Getting the source files when building from source, and R Windows FAQ for adding pre-compiled support to binary versions.
For `x86_64' and `ix86' processors under Linux there is
the AMD Core Math Library (ACML) www.amd.com/acml. For the gcc version we could use
--with-blas="-lacml"
if the appropriate library directory (such as
/opt/acml3.5.0/gfortran64/lib) is in the LD_LIBRRARY_PATH. For
other compilers, see the ACML documentation. Although the documentation
is unclear, 32-bit versions of ACML do run on other `ia32' chips
such as AthlonMP and P4. There is a multithreaded version of ACML
available for gfortran which makes use of libgomp (and
the latter must be installed).
See see Shared BLAS for an alternative way to use ACML.
ACML can be used on Windows when building from source.
Another tuned BLAS which is available for some processors11
under Linux, FreeBSD and MacOS X is by Kazushige Goto. This has been
made available in several formats, and is currently (April 2006)
available only as source code. For academic use only (after
registering) it can be obtained via
www.tacc.utexas.edu/resources/software/software.php. Once this
is built and installed, it can be used by configuring with
--with-blas="-lgoto"
It has been reported that on some RedHat-based Linux systems it is
necessary to set GOTO_NUM_THREADS=1 or OMP_NUM_THREADS=1
(to disable multiple threads) in the environment when using a
multi-threaded Goto BLAS, but others run happily with multiple threads.
Note that currently (July 2006) a multi-threaded Goto BLAS will be built by default if and only if the building is on a multi-processor system (counting multiple cores and hyperthreading), and at run time the default number of threads is the number of CPUs detected.
See see Shared BLAS for an alternative way to use the latest versions of the Goto BLAS.
For Intel processors under Linux, Intel's Math Kernel Library
(www.intel.com/software/products/mkl) can be used
by
--with-blas="-lmkl -lguide -lpthread"
This is multi-threaded, but the number of threads defaults to 1 (and can
be increased by setting OMP_NUM_THREADS).
(Thanks to Andy Liaw for the information.)
Note that the BLAS library will be used for many of the add-on packages as well as for R itself. This means that it is better to use a shared/dynamic BLAS library, as most of a static library will be compiled into the R executable and each BLAS-using package.
R 2.4.0 and later offer the option of compiling the BLAS into a
dynamic library libRblas stored in R_HOME/lib and
linking both R itself and all the add-on packages against that
library.
This is the default on most platforms unless an external BLAS is specified and found: for the latter it can be used by specifying the option --enable-BLAS-shlib, and it can always be disabled via --disable-BLAS-shlib.
This has both advantages and disadvantages.
libRblas, and that can be replaced. Note though that any dynamic
libraries the replacement links to will need to be found by the linker:
this may need the library path to be changed in etc/ldpaths.
Another option to change the BLAS in use is to symlink a dynamic BLAS library (such as ACML or Goto's) to R_HOME/lib/libRblas.so. For example, just
mv R_HOME/lib/libRblas.so R_HOME/lib/libRblas.so.keep
ln -s /opt/acml3.5.0/gfortran64_mp/lib/libacml.so R_HOME/lib/libRblas.so
will change the BLAS in use to multithreaded ACML. A similar link works for Goto 1.06 (even a multithreaded one, unlike Goto 1.00.) and MKL (provided the appropriate lib directory is in the run-time library path).
Provision is made for using an external LAPACK library, principally to
cope with BLAS libraries which contain a copy of LAPACK (such as
libsunperf on Solaris, vecLib on Mac OS X and ACML on
`ix86'/`x86_64' Linux). However, the likely performance
gains are thought to be small (and may be negative), and the default is
not to search for a suitable LAPACK library, and this is definitely
not recommended. You can specify a specific LAPACK library or
a search for a generic library by the configuration option
--with-lapack. The default for --with-lapack is to
check the BLAS library and then look for an external library
-llapack. Sites searching for the fastest possible linear
algebra may want to build a LAPACK library using the ATLAS-optimized
subset of LAPACK. To do so specify something like
--with-lapack="-L/path/to/libs -llapack -lcblas"
since the ATLAS subset of LAPACK depends on libcblas. A value
for --with-lapack can be set via the environment variable
LAPACK_LIBS, but this will only be used if --with-lapack
is specified (as the default value is no) and the BLAS library
does not contain LAPACK.
Since ACML contains a full LAPACK, if selected as the BLAS it can be used as the LAPACK via --with-lapack.
Intel's Math Kernel Library suppies a full LAPACK which can be used via
--with-lapack="-L/path/to/libs -lmkl_lapack64"
or `-lmkl_lapack32': library mkl_lapack is static and not
PIC. However, the version 8.0.1.006 we tested failed a regression test
in the complex LAPACK.
If you do use --with-lapack, be aware of potential problems
with bugs in the LAPACK 3.0 sources (or in the posted corrections to those
sources). In particular, bugs in DGEEV and DGESDD have
resulted in error messages such as
DGEBRD gave error code -10
(seen with the Debian -llapack which was current in late 2002,
Fedora Core 4 Extras -llapack in September 2005 and 64-bit
libsunperf in Forte 7). Other potential problems are incomplete
versions of the libraries: for example libsunperf from Sun Forte
6.x was missing the entry point for DLANGE and vecLib has
omitted the BLAS routine LSAME. For problems compiling LAPACK
using recent versions of gcc on `ix86' Linux, see
New platforms: these problems have surfaced in Fedora Core 3's
distribution, for example.
Please do bear in mind that using --with-lapack is `definitely not recommended': it is provided only because it is necessary on some platforms.
As with all libraries, you need to ensure that they and R were
compiled with compatible compilers and flags. For example, this means
that on Sun Sparc using the native compilers the flag -dalign
is needed so libsunperf can be used.
On some systems it is necessary that an external BLAS/LAPACK was built with the same FORTRAN compiler used to build R: known problems are with R built with gfortran, see Using gfortran.
configure has many options: running
./configure --help
will give a list. Probably the most important ones not covered elsewhere are (defaults in brackets)
Rprof() [yes]
You can use --without-foo or --disable-foo for the negatives.
You will want to use --disable-R-profiling if you are building a profiled executable of R (e.g. with `-pg)'.
Flag --enable-R-shlib causes the make process to build R as a dynamic (shared) library, typically called libR.so, and link the main R executable R.bin against that library. This can only be done if all the code (including system libraries) can be compiled into a dynamic library, and there may be a performance12 penalty. So you probably only want this if you will be using an application which embeds R. Note that C code in packages installed on an R system linked with --enable-R-shlib is linked against the dynamic library and so such packages cannot be used from an R system built in the default way.
If you need to re-configure R with different options you may need to run
make clean or even make distclean before doing so.
R can be compiled with support for multi-byte character sets (MBCS), in particular for UTF-8 locales (which are usually identified by suffix `.utf8', something like `en_GB.utf8'13. UTF-8 is an encoding of Unicode and in principle covers all human languages simultaneously: however, a given system may not have fonts capable of displaying more than a few of these languages.
Support for MBCS is selected if possible at configure time
(unless disabled with --disable-mbcs). This will check for a
large number of features, notably support for the C99/UNIX98 wide
character functions, for UTF-8 or MBCS support in X11 and for
iconv with a rich enough functionality. If enough of these
are found, MBCS will be listed as one of the “Additional
capabilities”. Then if R is started in a UTF-8 locale it assumes
that the terminal will supply and display UTF-8-encoded
characters14.
If run in a single-byte locale, R behaves almost exactly as if it was
configured with --disable-mbcs.
A version of R built with MBCS support can also be run in other multi-byte locales, for example those using the EUC-JP, EUC-KR and EUC-TW encodings on Unix-alikes and the code pages for Chinese, Japanese and Korean on Windows.
Translation of messages is supported via GNU gettext unless
disabled by the configure option --disable-nls or the
underlying OS has insufficiently standard C functions to support it.
The configure report will show NLS as one of the
`Additional capabilities' if support has been compiled in, and running
in an English locale (but not the C locale) will include
Natural language support but running in an English locale
in the greeting on starting R.
If you need or want to set certain configure variables to something other than their default, you can do that by either editing the file config.site (which documents all the variables you might want to set) or on the command line as
./configure VAR=value
If you are building in a directory different from the sources, there can be copies of config.site in the source and the build directories, and both will be read (in that order). To force a single file to be read, set the environment variable CONFIG_SITE to the location of the file.
These variables are precious, implying that they do not have to be exported to the environment, are kept in the cache even if not specified on the command line and checked for consistency between two configure runs (provided that caching is used), and are kept during automatic reconfiguration as if having been passed as command line arguments, even if no cache is used.
See the variable output section of configure --help for a list of
all these variables.
If you find you need to alter configure variables, it is worth noting that some settings may be cached in the file config.cache, and it is a good idea to remove that file (if it exists) before re-configuring. Note that caching is turned off by default: use the command line option --config-cache (or -C) to enable caching.
One common variable to change is R_PAPERSIZE, which defaults to `a4', not `letter'. (Valid values are `a4', `letter', `legal' and `executive'.)
This is used both when configuring R to set the default, and when running R to override the default. It is also used to set the papersize when making DVI and PDF manuals.
The configure default will most often be `a4' if R_PAPERSIZE is unset. (If the (Debian Linux) program paperconf is found or the environment variable PAPERSIZE is set, these are used to produce the default.)
Another precious variable is R_BROWSER, the default browser, which should take a value of an executable in the user's path or specify a full path.
If you have libraries and header files, e.g., for GNU
readline, in non-system directories, use the variables LDFLAGS
(for libraries, using `-L' flags to be passed to the linker) and
CPPFLAGS (for header files, using `-I' flags to be passed to
the C/C++ preprocessors), respectively, to specify these locations.
These default to `-L/usr/local/lib' (LDFLAGS,
`-L/usr/local/lib64' on most 64-bit Linux OSes) and
`-I/usr/local/include' (CPPFLAGS) to catch the most common
cases. If libraries are still not found, then maybe your
compiler/linker does not support re-ordering of -L and
-l flags (this has been reported to be a problem on HP-UX with
the native cc). In this case, use a different compiler (or a
front end shell script which does the re-ordering).
These flags can also be used to build a faster-running version of R.
On most platforms using gcc, having `-O3' in
CFLAGS and FFLAGS produces worthwhile performance gains.
On systems using the GNU linker (especially those using R as a shared
library), it is likely that including `-Wl,-O1' in LDFLAGS
is worthwhile, and on recent systems15
`'-Bdirect,--hash-style=both,-Wl,-O1'' is recommended at
http://lwn.net/Articles/192624/
The default settings for making the manuals are controlled by R_RD4PDF, R_RD4DVI and R_PAPERSIZE.
To compile R, you will most likely find it easiest to use GNU make. On Solaris 2.6/7/8 in particular, you need a version of GNU make different from 3.77; 3.79.1 and later work fine, as does the Sun make. The native make is reported to fail on SGI Irix 6.5 and Alpha/OSF1 (aka Tru64).
To build in a separate directory you need a make that uses the
VPATH variable, for example GNU make, or Sun
make on Solaris 2.7/8/9 (but not earlier).
If you want to use a make by another name, for example if your
GNU make is called `gmake', you need to set the
variable MAKE at configure time, for example
./configure MAKE=gmake
To compile R, you need a FORTRAN compiler. The default
is to search for
f95, fort, xlf95,
ifort, ifc, efc, pgf95
lf95, gfortran, ftn, g95,
f90, xlf90, pghpf, pgf90,
epcf90,
g77, f77, xlf, frt,
pgf77, cf77, fort77, fl32,
af77 (in that order)16, and use whichever is found first; if none is found,
R cannot be compiled.
However, if CC is gcc, the matching FORTRAN compiler
(g77 for gcc 3 and gfortran for
gcc 4) is used if available.
The search mechanism can be changed using the configure variable
F77 which specifies the command that runs the FORTRAN 77
compiler. If your FORTRAN compiler is in a non-standard location, you
should set the environment variable PATH accordingly before
running configure, or use the configure variable F77 to
specify its full path.
If your FORTRAN libraries are in slightly peculiar places, you should also look at LD_LIBRARY_PATH or your system's equivalent to make sure that all libraries are on this path.
Note that only FORTRAN compilers which convert identifiers to lower case are supported.
You must set whatever compilation flags (if any) are needed to ensure
that FORTRAN integer is equivalent to a C int pointer and
FORTRAN double precision is equivalent to a C double
pointer. This is checked during the configuration process.
Some of the FORTRAN code makes use of COMPLEX*16 variables, which
is a Fortran 90 extension. This is checked for at configure
time17, but you may need to avoid
compiler flags18 asserting
FORTRAN 77 compliance.
For performance reasons19 you may want to choose a FORTRAN 90/95 compiler.
It is possible to use f2c, the FORTRAN-to-C converter
(www.netlib.org/f2c), via a
script. (An example script is given in scripts/f77_f2c: this can
be customized by setting the environment variables F2C,
F2CLIBS, CC and CPP.) You may need to ensure that the
FORTRAN type integer is translated to the C type int.
Normally f2c.h contains `typedef long int integer;', which
will work on a 32-bit platform but not on a 64-bit platform. If your
compiler is not gcc you will need to set FPICFLAGS
appropriately.
gfortran is the F95 compiler that is part of gcc 4.x.y.
There was a problem with the version in the gcc 4.0.0
release and most pre-releases. At least on `ix86' and
`x86_64' Linux and MacOS X the dynamic version of the FORTRAN
runtime libgfortran could not be used: if this is loaded
redirection of C stdin (which R uses in many of its scripts)
becomes non-functional. A workaround is to set the environment variable
GFORTRAN_STDIN_UNIT to -1, but versions before 10 April
2005 had another bug causing the setting to be ignored. Both problems
have been fixed for gcc 4.0.1. The version of
gfortran shipping with Fedora Core 4 seems to have the fixes
in place.
Some versions of g95 (from www.g95.org) have the same problem.
On Linux `x86_64' systems there is an incompatibility in the
return conventions for double-complex functions between
gfortran and g77 which results in the final example
in example(eigen) hanging or segfaulting under external BLASs
built under g77, as well as with earlier binary versions of Dr
Goto's BLAS. This should be detected by a configure test.
A wide range of flags can be set in the file config.site or as configure variables on the command line. We have already mentioned
CPPFLAGSLDFLAGSand others include
CFLAGSMAIN_CFLAGSSHLIB_CFLAGSFFLAGSSAFE_FFLAGSMAIN_FFLAGSSHLIB_FFLAGSMAIN_LDFLAGSSHLIB_LDFLAGSLIBnnCPICFLAGSFPICFLAGSCXXPICFLAGSFPICFLAGSDEFSLibrary paths specified as -L/lib/path in LDFLAGS are
collected together and prepended to LD_LIBRARY_PATH (or your
system's equivalent), so there should be no need for -R or
-rpath flags.
Variables such as CPICFLAGS are determined where possible by configure. Some systems allows two types of PIC flags, for example `-fpic' and `-fPIC', and if they differ the first allows only a limited number of symbols in a shared library. Since R as a shared library has about 6200 symbols, if in doubt use the larger version.
To compile a profiling version of R, one might for example want to use `MAIN_CFLAGS=-pg', `MAIN_FFLAGS=-pg', `MAIN_LDFLAGS=-pg' on platforms where `-pg' cannot be used with position-independent code.
Beware: it may be necessary to set CFLAGS and
FFLAGS in ways compatible with the libraries to be used: one
possible issue is the alignment of doubles, another is the way
structures are passed.
On some platforms configure will select additional flags for
CFLAGS, CPPFLAGS, FFLAGS, CXXFLAGS and
LIBS in R_XTRA_CFLAGS (and so on). These are for options
which are always required, for example to force IEC 60559
compliance.
This section provides some notes on building R on different Unix-like platforms. These notes are based on tests run on one or two systems in each case with particular sets of compilers and support libraries. Success in building R depends on the proper installation and functioning of support software; your results may differ if you have other versions of compilers and support libraries.
The `X11()' graphics device is the one started automatically on Unix-alikes when plotting. As its name implies, it displays on a (local or remote) X server, and relies on the services and in particular the fonts provided by the X server. So if you sometimes use R at a consol