\input texinfo
@c %**start of header
@setfilename R-admin.info
@settitle R Installation and Administration
@setchapternewpage on
@c %**end of header

@syncodeindex fn vr

@dircategory Programming
@direntry
* R Administration: (R-admin).      R Installation and Administration.
@end direntry

@finalout

@include R-defs.texi
@include version.texi

@ifinfo
This is a guide to installation and administration for R.

@Rcopyright{2001}

@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries a copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).

@end ignore

@permission{}
@c ---------- ^- read that
@end ifinfo

@titlepage
@title R Installation and Administration
@subtitle Version @value{VERSION}
@author R Development Core Team
@page
@vskip 0pt plus 1filll
@permission{}

@Rcopyright{2001}

@value{ISBN-admin}
@end titlepage

@ifnothtml
@contents
@end ifnothtml

@ifnottex
@node Top, Obtaining R, (dir), (dir)
@top R Installation and Administration

This is a guide to installation and administration for R.

The current version of this document is @value{VERSION}.

@value{ISBN-admin}
@end ifnottex

@menu
* Obtaining R::                 
* Installing R under Unix-alikes::  
* Installing R under Windows::  
* Installing R under Mac OS X::  
* Running R::                   
* Add-on packages::             
* Internationalization::        
* Choosing between 32- and 64-bit builds::  
* Essential and useful other programs under Unix::  
* Configuration on Unix::       
* Platform notes::              
* Enabling search in HTML help::  
* The Windows toolset::         
* Function and variable index::  
* Concept index::               
@end menu

@node Obtaining R, Installing R under Unix-alikes, Top, Top
@chapter Obtaining R
@cindex Obtaining R

Sources, binaries and documentation for @R{} can be obtained via
@acronym{CRAN}, the ``Comprehensive R Archive Network'' whose current
members are listed at @url{http://cran.r-project.org/mirrors.html,
@code{cran.r-project.org/@/mirrors.html}}.

@menu
* Getting and unpacking the sources::  
* Getting patched and development versions::  
@end menu

@node Getting and unpacking the sources, Getting patched and development versions, Obtaining R, Obtaining R
@section Getting and unpacking the sources
@cindex Sources for R

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

@example
tar xvfz R-@var{x}.@var{y}.@var{z}.tar.gz
@end example

@noindent
on systems that have @acronym{GNU} @command{tar} installed.  On other
systems you need at least to have the @command{gzip} program installed.
Then you can use

@example
gzip -dc R-@var{x}.@var{y}.@var{z}.tar.gz | tar xvf -
@end example

The pathname of the directory into which the sources are unpacked should
not contain spaces, as @command{make} (specifically @acronym{GNU}
@command{make} 3.80) does not expect spaces.

If you need to transport the sources on floppy disks, you can download
the @file{R-@var{x}.@var{y}.@var{z}.tar.gz-split.*} files and paste them
together at the destination with (Unix)

@example
cat R-@var{x}.@var{y}.@var{z}-split.* > R-@var{x}.@var{y}.@var{z}.tar.gz
@end example

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


@node Getting patched and development versions,  , Getting and unpacking the sources, Obtaining R
@section Getting patched and development versions

A patched version of the current release, @samp{r-patched} and the
current development version, @samp{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, @samp{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
@url{ftp://ftp.stat.math.ethz.ch/pub/Software/R/,
@code{ftp://ftp.stat.math.ethz.ch/@/pub/@/Software/R/}}.  Download
either @file{R-patched.tar.gz} or @file{R-devel.tar.gz} (or the
@file{.tar.bz2} versions) and unpack as described in the previous
section.  They are built in exactly the same way as distributions of R
releases.

@menu
* Using Subversion and rsync::  
@end menu

@node Using Subversion and rsync,  , Getting patched and development versions, Getting patched and development versions
@subsection Using Subversion and rsync
@cindex Subversion

Sources are also available via @url{https://svn.R-project.org/R/}, the R
Subversion repository.  If you have a Subversion client (see
@url{http://subversion.tigris.org/, @code{subversion.tigris.org}}), you
can check out and update the current r-devel from
@url{https://svn.r-project.org/R/trunk/} and the current r-patched from
@samp{https://svn.r-project.org/R/branches/R-@var{x}-@var{y}-patches/}
(where @var{x} and @var{y} are the major and minor number of the current
released version of R).  E.g., use

@example
svn checkout https://svn.r-project.org/R/trunk/ @var{path}
@end example

@noindent
to check out r-devel into directory @var{path}.

Note that @samp{https:} is required, and that the SSL certificate for
the Subversion server of the R project is

@example
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
@end example

@noindent
(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.@: @command{wget -r} or
@command{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 @command{rsync} or
downloaded from @acronym{CRAN}.  To use @code{rsync} to install the
appropriate sources for the recommended packages, run
@code{./tools/rsync-recommended} from the top-level of the @R{} sources.

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

@example
wget -r -l1 --no-parent -A\*.gz -nd -P src/library/Recommended \
  http://CRAN.R-project.org/src/contrib/@var{dir}
./tools/link-recommended
@end example



@node Installing R under Unix-alikes, Installing R under Windows, Obtaining R, Top
@chapter Installing R under Unix-alikes
@cindex Installing under Unix-alikes

@R{} will configure and build under a number of common Unix and
Unix-alike platforms including @samp{@var{cpu}-*-linux-gnu} for the
@cputype{alpha}, @cputype{arm}, @cputype{hppa}, @cputype{ix86},
@cputype{ia64}, @cputype{m68k}, @cputype{mips}, @cputype{mipsel},
@cputype{powerpc}, @cputype{s390}, @cputype{sparc}, and @cputype{x86_64}
CPUs,
@c (see e.g.@:  @url{http://buildd.debian.org/build.php?&pkg=r-base}),
@c Actually, see http://packages.debian.org/unstable/math/r-base-core as
@c the build daemon is not used for all platforms; note also that Debian
@c has x86_64 <=> amd, ix86 <=> i386.
@samp{powerpc-apple-darwin} and @samp{sparc-@/sun-@/solaris}, as well as
probably (it is tested less frequently on these platforms)
@samp{i386-@/*-@/freebsd}, @samp{i386-@/*-@/netbsd},
@samp{i386-@/*-@/openbsd}, @samp{i386-@/sun-@/solaris},
@samp{mips-@/sgi-@/irix}, @samp{alpha-@/dec-@/osf*},
@samp{rs6000-@/ibm-@/aix}, and @samp{hppa-@/hp-@/hpux}.

@cindex Linux
@cindex Mac OS X
In addition, binary distributions are available for some common Linux
distributions and for Mac OS X (on PowerPC).  See the @acronym{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.

@menu
* Simple compilation::          
* Making the manuals::          
* Installation::                
* Uninstallation::              
* Sub-architectures::           
@end menu

@node Simple compilation, Making the manuals, Installing R under Unix-alikes, Installing R under Unix-alikes
@section Simple compilation

First review the essential and useful tools and libraries in
@ref{Essential and useful other programs under Unix}, and install those you
want or need.  Ensure that the environment variable @env{TMPDIR} is
either unset (and @file{/tmp} exists and can be written in and executed
from) or points to a valid temporary directory.

@findex R_HOME
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 @var{R_HOME}.  Untar the source code.  This should create
directories @file{src}, @file{doc}, and several more.  (At this point
North American readers should consult @ref{Setting paper size}.)  Issue
the following commands:

@findex configure

@example
./configure
make
@end example

@noindent
(See @ref{Using make} if your make is not called @samp{make}.)

Then check the built system works correctly, by

@example
make check
@end example

@noindent
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

@example
make check FORCE=FORCE
@end example

More comprehensive testing can be done by

@example
make check-devel
@end example

@noindent
or

@example
make check-all
@end example

@noindent
see @file{tests/README}.

If the command @command{configure} and @command{make} commands execute
successfully, the @R{} binary will be copied to
@file{@var{R_HOME}/bin/exec/R}.  In addition, a shell-script front-end
called @file{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 @file{/usr/local/bin/R}.  You could also copy the man page @file{R.1}
to a place where your @command{man} reader finds it, such as
@file{/usr/local/man/man1}.  If you want to install the complete @R{}
tree to, e.g., @file{/usr/local/lib/R}, see @ref{Installation}.  Note:
you do not @emph{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, @file{@var{TOP_SRCDIR}}).  To build in
@file{@var{BUILDDIR}}, run

@findex configure

@example
cd @var{BUILDDIR}
@var{TOP_SRCDIR}/configure
make
@end example

@noindent
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 @acronym{GNU} @command{make} to allow this, and the
pathname of the build directory should not contain spaces.)

@cindex Help pages
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 @code{make help}, @code{make html}
and @code{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 @acronym{CRAN}.

For those obtaining @R{} @emph{via} Subversion, one additional step is
necessary:
@cindex Vignettes
@cindex Subversion

@example
make vignettes
@end example

@noindent
which makes the @pkg{grid} vignettes (which are contained in the
tarballs):  it takes several minutes.

Now @code{rehash} if necessary, type @kbd{R}, and read the @R{} manuals
and the @R{} @acronym{FAQ} (files @file{FAQ} or
@file{doc/manual/R-FAQ.html}, or
@url{http://CRAN.R-project.org/doc/FAQ/R-FAQ.html,
@code{CRAN.R-project.org/@/doc/@/FAQ/@/R-FAQ.html}} which always has
the latest version).

@node Making the manuals, Installation, Simple compilation, Installing R under Unix-alikes
@section Making the manuals
@cindex Manuals

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

@table @samp
@item refman
Printed versions of all the help pages.
@item R-FAQ
R @acronym{FAQ}
@item R-intro
``An Introduction to R''.
@item R-data
``R Data Import/Export''.
@item R-admin
``R Installation and Administration'', this manual.
@item R-exts
``Writing R Extensions''.
@item R-lang
``The R Language Definition''.
@end table

@noindent
To make these, use

@example
make dvi      @r{to create DVI versions}
make pdf      @r{to create PDF versions}
make info     @r{to create info files (not @samp{refman}).}
@end example

You will not be able to build the info files unless you have
@command{makeinfo} version 4.7 or later installed.

The DVI versions can be previewed and printed using standard programs
such as @command{xdvi} and @command{dvips}.  The PDF versions can be
viewed using Acrobat Reader or (fairly recent versions of)
@command{xpdf} and @command{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 @acronym{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 @env{R_PAPERSIZE}
on the @command{make} command line, or setting @env{R_PAPERSIZE} in the
environment and using @command{make -e}.  (If re-making the manuals for
a different papersize, you should first delete the file
@file{doc/manual/version.texi}.)

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

@table @code
@item times
(The default.) Using standard PostScript fonts.  This works well both
for on-screen viewing and for printing, and is the default.  The one
disadvantage is that the Usage and Examples sections may come out rather
wide.

@item lm
Using the @emph{Latin Modern} fonts.  These are not often installed as
part of a @TeX{} distribution, but can obtained from
@url{http://www.ctan.org/tex-archive/fonts/ps-type1/lm,
@code{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 @code{times}.

@item cm-super
Using type-1 versions of the Computer Modern fonts by Vladimir Volovich.
This is a large installation, obtainable from
@url{http://www.ctan.org/tex-archive/fonts/ps-type1/cm-super,
@code{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 so readable on-screen as the other three options.

@item 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, @file{tctt0900.600pk}, @file{tctt1000.600pk} and
@file{tcrm1000.600pk}.  Unfortunately, if those files are not available,
Acrobat Reader will substitute completely incorrect glyphs so you need
to examine the logs carefully.  This was the default in @R{} version
1.x.y.
@end table

The default can be overridden by setting the environment variable
@env{R_RD4PDF}.  (On Unix, this will be picked up at install time.)  The
default value is @code{times,hyper}: omit @code{hyper} if you do not
want hyperlinks, e.g.@: for printing.


@node Installation, Uninstallation, Making the manuals, Installing R under Unix-alikes
@section Installation
@cindex Installation

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

After

@findex configure
@example
./configure
make
make check
@end example

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

@example
make install
@end example

@noindent
This will install to the following directories:

@table @asis
@item @file{@var{prefix}/bin} or @file{@var{bindir}}
the front-end shell script
@item @file{@var{prefix}/man/man1} or @file{@var{mandir}/man1}
the man page
@item @file{@var{prefix}/@var{LIBnn}/R} or @file{@var{libdir}/R}
all the rest (libraries, on-line help system, @dots{}).  Here
@var{LIBnn} is usually @samp{lib}, but may be @samp{lib64} on some
64-bit Linux systems.
@end table

@noindent
where @var{prefix} is determined during configuration (typically
@file{/usr/local}) and can be set by running @command{configure} with
the option @option{--prefix}, as in

@findex configure
@example
./configure --prefix=/where/you/want/R/to/go
@end example

@noindent
This causes @command{make install} to install the @R{} executable to
@file{/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 @command{configure}.  You can install into
another directory tree by using

@example
make prefix=/path/to/here install
@end example

@noindent
at least with GNU @command{make}.

More precise control is available at configure time via options: see
@command{configure --help} for details.  (However, many of them are
currently unused.)

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

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

All of @code{bindir} and @code{mandir} and @code{libdir} can also be
specified on the @command{make install} command line.

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

If you have made @R{} as a shared/dynamic library you can install it in
your system's library directory by

@example
make prefix=/path/to/here install-libR
@end example

@noindent
where @code{prefix} is optional, and @code{libdir} will give more
precise control.


@cindex Manuals, installing

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

@example
make install-dvi
make install-info
make install-pdf
@end example

@noindent
Once again, it is optional to specify @code{prefix}.  

More precise control is possible.  For info, the setting used is that of
@code{infodir} (default @samp{@var{prefix}/info}, set by configure
option @option{--infodir}).  The DVI and PDF files are installed into
the @R{} @file{doc} tree, set by the @command{make} variable
@code{rdocdir}.

@node Uninstallation, Sub-architectures, Installation, Installing R under Unix-alikes
@section Uninstallation

You can uninstall @R{} by

@example
make uninstall
@end example

@noindent
specifying @code{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
@file{doc/manual/Makefile}.


@node Sub-architectures,  , Uninstallation, Installing R under Unix-alikes
@section 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 Solaris for different chips (in particular, 32- and 64-bit
builds), 64- and 32- bit builds on @cputype{x86_64} Linux and different
CPUs (@cputype{ppc}, @cputype{ppc64} and @cputype{i386}) under MacOS
10.4.

@R{} supports the idea of architecture-specific builds, specified by
adding @samp{r_arch=@var{name}} to the @command{configure} line.  Here
@var{name} can be anything non-empty, and is used to name subdirectories
of @file{lib}, @file{etc}, @file{include} and @file{libs}.  Example
names from other systems are the use of @file{sparcv9} on Solaris and
@file{32} by @code{gcc} on @cputype{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 @samp{r_arch}).  The space savings
can be considerable: on @cputype{x86_64} Linux a basic install (without
debugging symbols) took 63Mb, and adding a 32-bit build added 6Mb.  If
you have installed multiple build you can select which build to run by

@example
R --arch=@var{name}
@end example

@noindent
and running @samp{R} will run the last build that was installed.

@code{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 @code{configure}
script or a @file{src/Makefile} file.  In such cases you can install for
extra builds by

@example
R --arch=@var{name} CMD INSTALL --libs-only @var{pkg(s)}
@end example


@node Installing R under Windows, Installing R under Mac OS X, Installing R under Unix-alikes, Top
@chapter Installing R under Windows
@cindex Installing under Windows

The @file{bin/windows} directory of a @acronym{CRAN} site contains
binaries for a base distribution and a large number of add-on packages
from @acronym{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 @emph{via} the installer @file{@value{RWVERSION}.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 @url{http://CRAN.R-project.org/bin/windows/base/rw-FAQ.html, R Windows
@acronym{FAQ}} for more details.

@menu
* Building from source::        
@end menu

@node Building from source,  , Installing R under Windows, Installing R under Windows
@section Building from source

@menu
* Getting the tools::           
* Getting the source files::    
* Building the core files::     
* Building the bitmap files::   
* Checking the build::          
* Building the manuals::        
* Building the Inno Setup installer::  
* Building the MSI installer::  
* Cross-building on ix86 Linux::  
@end menu

@node Getting the tools, Getting the source files, Building from source, Building from source
@subsection 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 @ref{The
Windows toolset} (and perhaps updates in
@url{http://www.murdoch-sutherland.com/Rtools/,
@code{www.murdoch-sutherland.com/Rtools}}) for details.

Be sure to set your path in the order given in the appendix.

@node Getting the source files, Building the core files, Getting the tools, Building from source
@subsection Getting the source files

You need to collect the following sets of files:
@itemize

@item
Get the @R{} source code @file{R-@value{VERSIONno}.tar.gz} from
@acronym{CRAN}.  Open a command window (or another shell) at a
directory @emph{whose path does not contain spaces}.  We will call this
directory @var{R_HOME} below.  Run

@example
tar zxvf R-@value{VERSIONno}.tar.gz
@end example

@noindent
to create the source tree in @var{R_HOME}.  @strong{Beware}: do use
@command{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 
@ref{Obtaining R} for details.

@item
Extract the international character support file @file{iconv.dll} from
@url{http://www.murdoch-sutherland.com/Rtools/iconv.zip,
@code{www.@/murdoch-@/sutherland.com/@/Rtools/@/iconv.zip}} and put it in
@file{@var{R_HOME}/@/src/@/gnuwin32/@/unicode}.

@item
The TclTk support files are in
@url{http://www.murdoch-sutherland.com/Rtools/R_Tcl.zip,
@code{www.murdoch-sutherland.com/@/Rtools/@/R_Tcl.zip}}: unzip this in
@var{R_HOME}, and it will add directories @file{@var{R_HOME}/Tcl},
@file{@var{R_HOME}/Tcl/bin}, etc.

@item
You need @code{libpng} and @code{jpeg} sources (available, e.g., from
@url{http://www.libpng.org, @code{www.libpng.org}},
@url{ftp://ftp.uu.net/graphics/}[png,jpeg].  You will need files
@file{libpng-1.2.8.tar.gz} and @file{jpegsrc.v6b.tar.gz} or later.

@item
If you are not using a tarball you need to obtain copies of the
recommended packages from @acronym{CRAN}.  Put the @file{.tar.gz} files
in @file{@var{R_HOME}/src/library/Recommended} and run @code{make
link-recommended}.  If you have @command{rsync} and an Internet
connection, you can do this automatically using

@example
make rsync-recommended
@end example

@item
Optionally, you can install a version of ATLAS
(@url{http://math-atlas.sourceforge.net/,
@code{math-atlas.sourceforge.net}}) tuned to your system for fast linear
algebra routines. Pre-built @file{Rblas.dll} for various Pentium and
AthlonXP chips are available in the @file{windows/contrib/ATLAS} area on
@acronym{CRAN}.  If you are building R from source, there are macros
@code{USE_ATLAS} and @code{ATLAS_PATH} in the file @file{MkRules}.  Set
@code{USE_ATLAS = YES} and @code{ATLAS_PATH} to where the ATLAS
libraries are located.  You will need to make the libraries
yourself@footnote{We do this using the Cygwin compilers, often with
some difficulty.}: none of the binaries we have seen are compiled for
the correct compiler.  Since @R{} has its own @samp{xerbla} it is best
to delete that in ATLAS by

@example
ar d /path/to/libf77blas.a xerbla.o
@end example

Another possibility is to use AMD's AMD Core Math Library (ACML)
@url{http://www.amd.com/acml, @code{www.amd.com/@/acml}}.  To use the
Cygwin-compiled version (Cygwin itself is not needed, at least
currently), install @file{acml-3-5-0-win32-g77.exe} (or later) and edit
@file{@var{R_HOME}/@/src/@/gnuwin32/MkRules} to define
@code{USE_ACML=YES} and set @code{ACML_PATH} to the path to
@file{libacml.a}.  If you also set @code{USE_ACML_LAPACK=YES}, ACML will
be used to provide the LAPACK library for R itself and any packages
using @code{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.

@end itemize

@node Building the core files, Building the bitmap files, Getting the source files, Building from source
@subsection Building the core files

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

Open a command window at @file{@var{R_HOME}/src/gnuwin32}.  Edit
@file{MkRules} to set the appropriate paths as needed and to set the
type(s) of help that you want built.  @strong{Beware}: @file{MkRules}
contains tabs and some editors (e.g., WinEdt) silently remove them.
Then run

@example
make all recommended
@end example

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

Notes:
@itemize
@item
The file @file{bin/Rchtml.dll} is only built if CHM help is specified in
@file{MkRules}. Its source is in the help directory, and you need the
@HTML{} Help Workshop files to build it.  You can just copy this from a
binary distribution.

@item
We have had reports that earlier versions of anti-virus software locking
up the machine, but not for several years.  However, aggressive
anti-virus checking such as the on-access scanning of Sophos can slow
the build down several-fold.

@item
By default Doug Lea's @code{malloc} in the file
@file{@var{R_HOME}/src/gnuwin32/malloc.c} is used for R's internal memory
allocations.  You can opt out of this by commenting the line
@code{LEA_MALLOC=YES} in @file{MkRules}, in which case the
@code{malloc} in @file{msvcrt.dll} is used.  This does work but
imposes a considerable performance penalty.

@item
You can run a parallel make by e.g.

@example
make -j2 all
make recommended
@end example

@noindent
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.

@end itemize

@node Building the bitmap files, Checking the build, Building the core files, Building from source
@subsection Building the bitmap files
@cindex Rbitmap.dll

The file @file{@var{R_HOME}/bin/Rbitmap.dll} is not built automatically.
Working in the directory @file{@var{R_HOME}/src/gnuwin32/bitmap},
install the @code{libpng} and @code{jpeg} sources in sub-directories.
The @code{libpng} sub-directory must be named @file{libpng} (as required
by the @code{libpng} documentation).  The @code{jpeg} sub-directory for
version 6b is named @file{jpeg-6b}; if you use a different version, edit
@file{Makefile} and change the definition of @code{JPEGDIR}.

Example:

@example
> tar xzvf libpng-1.2.8.tar.gz
> mv libpng-1.2.8 libpng
> tar xzvf jpegsrc.v6b.tar.gz
@end example

Once everything is set up in directory @file{bitmap}, @code{make}
in that directory or @code{make bitmapdll} in the parent directory
should build @file{Rbitmap.dll} and install it in @file{@var{R_HOME}/bin}.

@node Checking the build, Building the manuals, Building the bitmap files, Building from source
@subsection Checking the build

You can test a build by running @code{make check}.  You may need to set
@env{TMPDIR} to the absolute path to a suitable temporary directory: the
default is @samp{c:/TEMP}.  (Use forward slashes and do not use a path
including spaces.)

The recommended packages can be  checked by

@example
make check-recommended
@end example

Other levels of checking are

@example
make check-devel
@end example

@noindent
for a more thorough check of the @R{} functionality, and

@example
make check-all
@end example

@noindent
for @code{check-devel} and @code{check-recommended}.


@node Building the manuals, Building the Inno Setup installer, Checking the build, Building from source
@subsection Building the manuals

The PDF manuals can be made by

@example
make manuals
@end example

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

@example
cd ../../doc/manual
make -f Makefile.win info
@end example

@noindent
To make DVI versions of the manuals use

@example
cd ../../doc/manual
make -f Makefile.win dvi
@end example

@noindent
(all assuming you have @command{tex} and @command{latex} installed and
in your path).

See the @ref{Making the manuals} section in the Unix section for
setting options such as the paper size.

@node Building the Inno Setup installer, Building the MSI installer, Building the manuals, Building from source
@subsection 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, as well as the recommended packages and
Inno Setup (@pxref{The Inno Setup installer}).

Once everything is set up

@example
make distribution
make check-all
@end example

@noindent
will make all the pieces and the installers and put them in the
@file{gnuwin32/cran} subdirectory, then check the build.  This works by
building all the parts in the sequence:

@example
Rpwd.exe @r{(a utility needed in the build)}
rbuild @r{(the executables, the @acronym{FAQ} docs etc.)}
rpackage @r{(the base packages)}
htmldocs @r{(the @acronym{HTML} documentation)}
bitmapdll @r{(the bitmap support files)}
recommended @r{(the recommended packages)}
vignettes @r{(the vignettes in package @strong{grid}:}
	  @r{ only needed if building from svn checkout)}
manuals @r{(the PDF manuals)}
rinstaller @r{(the install program)}
crandir @r{(the @acronym{CRAN} distribution directory)}
@end example

The parts can be made individually if a full build is not needed, but
earlier parts must be built before later ones.  (The @file{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 @samp{make} is run.

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

@example
make rinstaller EXTRA_PKGS='pkg1 pkg2 pkg3'
@end example


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 @samp{Full Installation} from the
@samp{Select Components} screen), then add packages and make other
customizations to that installation.  Then in
@file{src/gnuwin32/installer} run

@example
make myR IMAGEDIR=rootdir
@end example

@noindent
where @file{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, @file{@value{RWVERSION}.exe}, so
please rename it to indicate that it is customized.

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

@example
make rinstaller MDISDI=1
@end example

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

@node Building the MSI installer, Cross-building on ix86 Linux, Building the Inno Setup installer, Building from source
@subsection 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 available from
@url{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 @file{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

@example
cd installer
make msi
@end example

@noindent
which will results in a file of about 40Mb with a name like
@file{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.

@node Cross-building on ix86 Linux,  , Building the MSI installer, Building from source
@subsection Cross-building on ix86 Linux

It is possible to cross-build @R{} or packages on @cputype{ix86} Linux,
and the @cputype{ix86} cross-compilers have also been used successfully
on @cputype{x86_64} Linux.

You will need i386-mingw32 cross-compilers installed and in your path.
There is currently a complete set of tools at
@url{http://www.stats.ox.ac.uk/pub/Rtools/mingw-cross5.tar.bz2,
@code{www.stats.ox.ac.uk/@/pub/@/Rtools/@/mingw-cross5.tar.bz2}} (Just
unpack this somewhere and put its @file{bin} directory in your path.)

You will need Perl, @command{zip} and @command{unzip} installed and
@command{makeinfo} version 4.7 or later (part of GNU @code{texinfo}).

You also need the R source (@file{R-@value{VERSIONno}.tar.gz}).

Then: untar @file{R-@value{VERSIONno}.tar.gz} somewhere, and

@example
cd /somewhere/R-@value{VERSIONno}/src/gnuwin32
@end example

Edit @file{MkRules} to set @code{BUILD=CROSS} and the appropriate
paths (including @code{HEADER}) as needed.

Edit @file{MkRules} to set the type(s) of help that you want built. (You
will not be able to cross-build @file{.chm} files, so @code{WINHELP} is
automatically set to @code{NO}.)

You also need a working copy of @emph{this version} of @R{} on Linux:
uncomment and set @code{R_EXE} in @file{MkRules} to point to it.

Then run @code{make} (and parallel make works reliably, unlike on Windows).

Packages can be made in the same way as natively: see @ref{Add-on packages}.

(It is possible to cross-build the installers using WINE, which we
leave as an exercise for the reader.)

To distribute a cross-build (or just to transfer it to a Windows machine
for testing) use

@example
cd installer
make imagedir
zip -r9X R-@value{VERSIONno}.zip R-@value{VERSIONno}  # or something similar
@end example

We have not found a reliable way to convert base to lazy-loading when
cross-building, so it is left in the old format.

Also based on this facility is
@url{http://cran.r-project.org/doc/contrib/Makefile-rcb,
@file{Makefile-rcb}} by J. Yan and A. J. Rossini.  For details, see the
Makefile itself, or
@uref{http://cran.r-project.org/doc/contrib/cross-build.pdf}.


@node Installing R under Mac OS X, Running R, Installing R under Windows, Top
@chapter Installing R under Mac OS X
@cindex Mac OS X

The @file{bin/macosx} directory of a @acronym{CRAN} site contains
binaries for MacOS X for a base distribution and a large number of
add-on packages from @acronym{CRAN} to run on Mac OS X version 10.3.0 or
higher.

The simplest way is to use @file{R.dmg}.  Just double-click on the
icon and the disk image file will be mounted. Read the
@file{ReadMe.txt} inside the disk image and follow the instructions.

See the @url{http://CRAN.R-project.org/bin/macosx/RMacOSX-FAQ.html, R
for Mac OS X @acronym{FAQ}} for more details.

@menu
* Building from source on Mac OS X::  
@end menu

@node Building from source on Mac OS X,  , Installing R under Mac OS X, Installing R under Mac OS X
@section Building from source on Mac OS X

If you want to build this port from the sources, you can read the above
mentioned @url{http://CRAN.R-project.org/bin/macosx/RMacOSX-FAQ.html, R
for Mac OS X @acronym{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

@example
tar zxvf R-@value{VERSIONno}.tar.gz
cd R-@value{VERSIONno}
./configure --with-blas='-framework vecLib' --with-lapack \
  --with-aqua --enable-R-framework
make
@end example

@noindent
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 @code{R.app} Console, and imply
@option{--enable-R-shlib} to build @R{} as a shared/dynamic library.

These options configure @R{} to be built and installed as a framework
called @file{R.framework}.  The default path for @file{R.framework} is
@file{/Library/Frameworks} but this can be changed at configure time
specifying the flag @option{--enable-R-framework[=@var{DIR}]} or at
install time as

@example
make prefix=/where/you/want/R.framework/to/go install
@end example

@noindent
the @file{R.framework} has not to be specified in the path.

@node Running R, Add-on packages, Installing R under Mac OS X, Top
@chapter Running R

How to start @R{} and what command-line options are available is discussed
in @ref{Invoking R, , Invoking R, R-intro, An Introduction to R}.

@R{} makes use of a number of environment variables, the default values
of many of which are set in file @file{@var{R_HOME}/etc/Renviron} (there
are none set by default on Windows and hence no such file).  These are
set at @command{configure} time, and you would not normally want to
change them -- a possible exception is @env{R_PAPERSIZE} (@pxref{Setting
paper size}).  As from @R{} 2.4.0 the paper size will be deduced from
the @samp{LC_PAPER} locale category if it exists and @env{R_PAPERSIZE}
is unset, and this will normally produce the right choice from @samp{a4}
and @samp{letter} on modern Unix-alikes (but can always be overridden by
setting @env{R_PAPERSIZE}).

Various environment variables can be set to determine where @R{} creates
its per-session temporary directory.  The environment variables
@env{TMPDIR}, @env{TMP} and @env{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 @file{/tmp} on Unix-alikes and the value of
@env{R_USER} on Windows.

Some Unix-alike systems are set up to remove files and directories
periodically from @file{/tmp}, for example by a @command{cron} job
running @command{tmpwatch}.  Set @env{TMPDIR} to another directory
before running long-running jobs on such a system.

@node Add-on packages, Internationalization, Running R, Top
@chapter Add-on packages
@cindex Packages

@menu
* Installing packages::         
* Updating packages::           
* Removing packages::           
* Setting up a package repository::  
@end menu

It is helpful to use the correct terminology.  A @emph{package} is
loaded from a @emph{library} by the function @code{library()}.  Thus a
library is a directory containing installed packages; the main library
is @file{@var{R_HOME}/library}, but others can be used, for example by
setting the environment variable @env{R_LIBS} or using the @R{} function
@code{.libPaths()}.

@node Installing packages, Updating packages, Add-on packages, Add-on packages
@section Installing packages
@cindex Packages, installing

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

@example
R CMD INSTALL -l /path/to/library @var{pkg1} @var{pkg2} @dots{}
@end example

@noindent
The part @samp{-l /path/to/library} can be omitted, in which case the
first library in @env{R_LIBS} is used if set, otherwise the main library
@file{@var{R_HOME}/library} is used.  (@env{R_LIBS} is looked for in the
environment: note that @file{.Renviron} is not read by @command{R CMD}.)
Ensure that the environment variable @env{TMPDIR} is either unset (and
@file{/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 @code{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 @ref{The Windows toolset}) installed.

@findex install.packages
Alternatively, packages can be downloaded and installed from within
@R{}.  First set the option @code{CRAN} to your nearest @acronym{CRAN}
mirror using @command{chooseCRANmirror()}.  Then download
and install packages @pkg{pkg1} and @pkg{pkg2} by

@example
> install.packages(c("pkg1", "pkg2"))
@end example

@noindent
Unless the library is specified (argument @code{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.

@example
> install.packages("Rcmdr", dependencies = TRUE)
@end example


What @code{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 @emph{source} packages on
@acronym{CRAN} (or other repository/ies), downloads the latest version
of the package sources, and installs them (via @code{R CMD INSTALL}).
On Windows it looks (by default) at the list of @emph{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 @code{type} argument.

@code{install.packages} can install a source package from a local
@file{.tar.gz} file by setting argument @code{repos} to @code{NULL}.

On Windows @code{install.packages} can also install a binary package
from a local @file{zip} file by setting argument @code{repos} to
@code{NULL}.   @code{Rgui.exe} has a menu @code{Packages} with a GUI
interface to @code{install.packages}, @code{update.packages} and
@code{library}.

@code{install.packages} can look in several repositories, specified as a
character vector by the argument @code{repos}: these can include a
@acronym{CRAN} mirror, Bioconductor, Omegahat, local archives, local
files, @dots{}).

On Mac OS X @code{install.packages} works as it does on other Unix-like
systems, but there is an additional type @code{mac.binary} that can be
passed to @code{install.package} in order to download and install binary
packages from @acronym{CRAN}. These Macintosh binary package files have
the extension @samp{tgz}.  The R GUI provides for installation of either
binary or source packages, from @acronym{CRAN} or local files.

@menu
* Customizing package compilation under Unix::  
* Customizing package compilation under Windows::  
@end menu

@node Customizing package compilation under Unix, Customizing package compilation under Windows, Installing packages, Installing packages
@subsection Customizing package compilation under Unix

The R system and package-specific compilation flags can be overridden or
added to by setting the appropriate Make variables in the personal file
@file{$HOME/.R/Makevars-$R_PLATFORM}, or if that does not exist,
@file{$HOME/.R/Makevars}, where @samp{R_PLATFORM} is the platform for
which R was built, as available in the @code{platform} component of the
R variable @code{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.@: @option{-Wall -pedantic} for tools from GCC, the Gnu
Compiler Collection.

@node Customizing package compilation under Windows,  , Customizing package compilation under Unix, Installing packages
@subsection Customizing package compilation under Windows
@findex MakeDll
@findex Makevars.win
@findex HELP
@findex HELPTYPES
@findex WINHELP

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 @file{README.packages} file.

The Makefiles can be customized: in particular the name of the DLL can
be set (for example we once needed @code{integrate-DLLNM=adapt}), the
compile flags can be set (see the examples in @file{MakeDll}) and the
types of help (if any) to be generated can be chosen (variables
@code{HELP}, @code{HELPTYPES} and @code{WINHELP}).  The simplest way to
customize the compilation steps is to set variables in a file
@file{src/Makevars.win}, which will automatically be included by
@file{MakeDLL}. For example, for RODBC @file{src/Makevars.win} could
include the line

@example
DLLLIBS+=-lodbc32
@end example

@noindent
or, equivalently,

@example
RODBC-DLLLIBS=-lodbc32
@end example

@noindent
but in fact contains the single line

@example
PKG_LIBS=-lodbc32
@end example

@noindent
If you have a file @file{src/Makefile.win}, that will be used as the
makefile for source compilation in place of our makefile and
@file{MakeDll} and @file{src/Makevars.win} will be ignored.

Package-specific compilation flags can be overridden or added to using
the personal file @file{$HOME/.R/Makevars.win}, or if that does not
exist, @file{$HOME/.R/Makevars}. (See the @file{rw-FAQ} for the meaning
of @code{$HOME}.)  For the record, the order of precedence is (last wins)
@itemize
@item
@file{MakeDll} and @file{MkRules}

@item
@file{src/Makefile}

@item
@file{src/Makevars.win} if it exists, otherwise @file{src/Makevars}

@item
@file{$HOME/.R/Makevars.win} if it exists, otherwise
@file{$HOME/.R/Makevars}.

@item
@file{src/Makefile.win} if present causes all of the above to be ignored.
@end itemize

@strong{Beware}: files @file{src/Makefile} or @file{src/Makevars} will
be used if they exist and the @file{.win} equivalents do not.  Such
files included in package sources are usually designed for use under
Unix and are best removed.

@strong{Beware}: references to variables in @file{R.dll} are converted to the
right form by using the header files.  You must include them.

For additional control, @file{@var{R_HOME}/src/gnuwin32/Makefile}
contains additional make targets corresponding to various options to
@code{R CMD INSTALL}.  These assume that package @code{foo}'s source
code has been installed in directory
@file{@var{R_HOME}/src/library/foo}. Then @code{make pkg-foo} is similar
to @code{R CMD INSTALL foo} (but the latter would require
@file{@var{R_HOME}/src/library} to be the current directory).  Other
targets are
@itemize
@item
@code{ziponly-foo}, to use zip to compress the help files after building
the package.
@item
@code{ziphelp-foo} to both compress the help files and to keep the
originals.
@item
@code{zipdata-foo} to compress the data files.  This is recommended if
you have either many small data files (as in package @pkg{Devore5}) or a
few large data files.
@item
@code{pkgcheck-foo} to check the package (like @code{R CMD CHECK foo}).
@end itemize

Using this approach allows variables to be set during the build, e.g.

@example
make PKGDIR=/mysources RLIB=/R/library pkg-foo
@end example

Some variables that may be used include:
@itemize
@item
@code{DEBUG=T} to compile with debugging information for @code{gdb}.
@item
@code{PKG_CFLAGS=} to specify options to the C compiler.
@item
@code{PKG_CPPFLAGS=} to specify options to the preprocessor.
@item
@code{PKG_CXXFLAGS=} to specify options to the C++ compiler.
@item
@code{PKG_FFLAGS=} to specify options to the FORTRAN 77 compiler.
@item
@code{PKG_FCFLAGS=} to specify options to the Fortran 95 compiler (if
specified).
@item
@code{PKG_LIBS=} to specify options to the linking step making the DLL.
@item 
@code{PKGDIR=/path/to/source} to specify the path to the package source files.
@item 
@code{RLIB=/path/to/library} to specify the path to the library
where the package should be installed.
@end itemize
For a complete list of variables, see the @file{M*} files in
@file{@var{R_HOME}/src/gnuwin32}.  The @code{PKG_*} flags are those
typically included in @file{Makevars} files.


@node Updating packages, Removing packages, Installing packages, Add-on packages
@section Updating packages
@findex update.packages
@cindex Packages, updating

The command @code{update.packages()} is the simplest way to ensure that
all the packages on your system are up to date.  Set the @code{repos}
argument as in the previous section.  The @code{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 @code{packageStatus()}, which returns an object with
information on all installed packages and packages available at multiple
repositories.  The @code{print} and @code{summary} methods give an
overview of installed and available packages, the @code{upgrade} method
offers to fetch and install the latest versions of outdated packages.


@node Removing packages, Setting up a package repository, Updating packages, Add-on packages
@section Removing packages
@findex remove.packages
@cindex Packages, removing

Packages can be removed in a number of ways.  From a command prompt they
can be removed by

@example
R CMD REMOVE -l /path/to/library @var{pkg1} @var{pkg2} @dots{}
@end example

From a running @R{} process they can be removed by

@example
> remove.packages(c("pkg1", "pkg2"),
                  lib = file.path("path", "to", "library"))
@end example

Finally, in most installations one can just remove the package directory
from the library.

@strong{Note}: only @code{remove.packages} can remove package
@emph{bundles}.


@node Setting up a package repository,  , Removing packages, Add-on packages
@section Setting up a package repository
@cindex Repositories

Utilities such as @code{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
@url{http://www.omegahat.org/R}: this must be an URL scheme that
@code{download.packages} supports (which also includes @samp{ftp://} and
@samp{file://}).  Under that base URL there should be directory trees
for one or more of the following types of package distributions:

@itemize
@item 
@code{"source"}: located at @file{src/contrib} and containing
@file{.tar.gz} files.

@item 
@code{"win.binary"}: located at @file{bin/windows/contrib/@var{x.y}} for
@R{} versions @var{x.y.z} and containing @file{.zip} files.

@item 
@code{"mac.binary"}: located at
@file{bin/macosx/powerpc/contrib/@var{x.y}} or
@file{bin/macosx/i686/contrib/@var{x.y}} for @R{} versions @var{x.y.z}
and containing @file{.tgz} files.
@end itemize

Each terminal directory must also contain a @file{PACKAGES} file.  This
can be a concatenation of the @file{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 @code{write_PACKAGES} in the @pkg{tools} package, and its
help explains which fields are needed.  Optionally there can also be
a @file{PACKAGES.gz} file, a @command{gzip}-compressed version of
@file{PACKAGES}.

To add your repository to the list offered by @code{setRepositories()},
see the help file for that function.

@node Internationalization, Choosing between 32- and 64-bit builds, Add-on packages, Top
@chapter Internationalization and Localization
@cindex Internationalization
@cindex Localization

@emph{Internationalization} refers to the process of enabling support
for non-English languages, and @emph{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.@: @code{postscript()} and @code{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) @command{configure} option
@option{--enable-mbcs}: @pxref{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
@cindex Locale
current @code{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{}.

@menu
* Locales::                     
* Localization of messages::    
@end menu

@node Locales, Localization of messages, Internationalization, Internationalization
@section Locales
@cindex Locale

A @emph{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 @code{Sys.getlocale} and
@code{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
@itemize
@item
A human language.  These are generally specified by a lower-case two-character
abbreviation following ISO 639.

@item
A `territory', used mainly to specify the currency. These are generally
specified by an upper-case two-character abbreviation following ISO
3166.  Sometimes the combination of language and territory is used to
specify the encoding, for example to distinguish between traditional and
simplified Chinese.

@item
A charset encoding, which determines both how a byte stream should be
divided into characters, and which characters the subsequences of bytes
represent.

@item
Optionally, a modifier, for example to indicate that Austria is to be
considered pre- or post-Euro.
@end itemize

@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.

@menu
* Locales under Linux::         
* Locales under Windows::       
* Locales under Mac OS X::      
@end menu

@node Locales under Linux, Locales under Windows, Locales, Locales
@subsection Locales under Linux

Modern Linux uses the XPG locale specifications which have the form
@samp{en_GB}, @samp{en_GB.utf8}, @samp{aa_ER.utf8@@saaho},
@samp{de_AT.iso885915@@euro}, the components being in the order listed
above.  (See @command{man locale} and @command{locale -a} for more
details.)  Similar schemes (but often in different cases) are used by
most Unix-alikes.

@node Locales under Windows, Locales under Mac OS X, Locales under Linux, Locales
@subsection Locales under Windows

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
@url{http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_language_and_country_strings.asp,
@code{msdn.microsoft.com/@/library/@/default.asp?url=/@/library/@/en-us/@/@/vccore98/@/html/@/_crt_language_and_country_strings.asp}}.

@node Locales under Mac OS X,  , Locales under Windows, Locales
@subsection Locales under Mac OS X

Mac OS X supports locales in its own particular way, but the R GUI tries
to make this easier for users. See
@url{http://developer.apple.com/documentation/MacOSX/Conceptual/BPInternational/,
@code{developer.apple.com/@/documentation/@/MacOSX/@/Conceptual/@/BPInternational/}}

@noindent
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 @code{UTF-8}).


@node Localization of messages,  , Locales, Internationalization
@section Localization of messages

The preferred language for messages is by default taken from the locale.
This can be overridden first by the setting of the environment variable
@env{LANGUAGE} and then by the environment variables @env{LC_ALL},
@env{LC_MESSAGES} and @env{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 @env{LC_ALL} do not all
correspond to XPG language names and so @env{LANGUAGE} may need to be
set.  (One example is @samp{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 @emph{via} @code{Sys.setlocale("LC_MESSAGES", "new_locale")},
but not by setting environment variables such as @env{LANGUAGE}.

Messages are divided into @emph{domains}, and translations may be
available for some or all messages in a domain.  @R{} makes use of the
following domains.

@itemize
@item
Domain @code{R} for basic C-level error messages.

@item
Domain @code{R-@var{pkg}} for the R @code{stop}, @code{warning} and
@code{message} messages in each package, including @code{R-base} for the
@code{base} package.

@item
Domain @code{@var{pkg}} for the C-level messages in each package.

@item
Domain @code{RGui} for the menus etc of the R for Windows GUI front-end.

@end itemize

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 (@samp{de_AT}) translation catalogue will be used in preference
to a generic German one (@samp{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 @samp{en_GB} that translate the Americanisms
(e.g., @samp{gray}) in the standard messages into English.  Two other
examples: there are catalogues for @samp{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 @samp{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
@env{LANGUAGE} variable (only) can be a colon-separated list, for
example @samp{se:de}, giving a set of languages in decreasing order of
preference.  One special value is @samp{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 @url{http://developer.r-project.org/Translations.html,
@code{developer.r-project.org/@/Translations.html}} for how to prepare
and install translation catalogues.

@node Choosing between 32- and 64-bit builds, Essential and useful other programs under Unix, Internationalization, Top
@chapter Choosing between 32- and 64-bit builds

@menu
* Windows::                     
@end menu

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
@cputype{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., @cputype{x86_64}) 64-bit is.

All current versions of @R{} use 32-bit integers and
@acronym{IEC}@tie{}60559@footnote{also known as @acronym{IEC}@tie{}559
and @acronym{IEEE}@tie{}754} double-precision reals, and so compute to
the same precision@footnote{at least when storing quantities: the on-FPU
precision is allowed to vary} 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:
@itemize
@item
The total virtual memory space made available to a 32-bit
process@footnote{until recently this limit applied to all processes, not
just to one process} is limited to 4GB, and on most OSes to 3GB (or even
2GB).  The limits for 64-bit processes are much larger.

@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).

@item
32-bit OSes by default limit file sizes to 2GB.  This can often be
worked around: and @command{configure} selects suitable defines if this
is possible.  (We have also largely worked around that limit on
Windows.)  64-bit builds have much larger limits.

@item
Because the pointers are larger, @R{}'s basic structure (the cons cell)
is larger (normally twice the size).  This means that @R{} objects take
more space and more time to manipulate, especially during garbage
collection. So 64-bit versions of @R{} will typically run slower than
32-bit versions. (On Sparc Solaris the difference was 15-20%, on
@cputype{x86_64} around 10%.)

@end itemize

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: @xref{Sub-architectures}.

Even on 64-bit builds of @R{} there are limits on the size of @R{}
objects (see @code{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
@math{2^{31}-1}, about 2 billion, and on 64-bit systems the size of a
block of memory allocated is limited to @math{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.

@node Windows,  , Choosing between 32- and 64-bit builds, Choosing between 32- and 64-bit builds
@section Windows

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.@footnote{It is likely that
commercial 64-bit compilers could be used, but those we have looked at
do not work in the same way as the MinGW compilers so extensive changes
to the build system would be needed.  Also, end users would need to have
the same compilers to install extension packages.}

@node Essential and useful other programs under Unix, Configuration on Unix, Choosing between 32- and 64-bit builds, Top
@appendix Essential and useful other programs under Unix

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
@command{configure}.

Remember that some package management systems (such as @acronym{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 @samp{-devel} or @samp{-dev}: you need both versions
installed.

@menu
* Essential programs::          
* Useful libraries and programs::  
* Linear algebra::              
@end menu

@node Essential programs, Useful libraries and programs, Essential and useful other programs under Unix, Essential and useful other programs under Unix
@section Essential programs

You need a means of compiling C and FORTRAN 77 (see @ref{Using
FORTRAN}).  Some add-on packages also need a C++ compiler.  Your C
compiler should be @acronym{IEC}@tie{}60059@footnote{also known as
@acronym{IEEE}@tie{}754}, 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 @code{CFLAGS} suitably.  For recent
versions of @command{gcc} with @code{glibc} this means including
@option{-std=gnu99} in @code{CFLAGS} (@option{-std=c99} excludes POSIX
functionality).

Unless you do not want to view graphs on-screen you need @samp{X11}
installed, including its headers and client libraries.  (On Fedora Core
Linux this means the @samp{xorg-x11-devel} and @samp{xorg-x11-libs}
RPMs, for example.  Older Linuxen used @samp{XFree86-}.  Some Debian
derivatives apparently also require @samp{libxt-dev}.)  If you really do
not want these you will need to explicitly configure @R{} without X11,
using @option{--with-x=no}.

The command-line editing depends on the @code{readline} library
available from any @acronym{GNU} mirror: you will need a fairly recent
version.  Otherwise you will need to configure with
@option{--with-readline=no} (or equivalent).

You will need Perl version 5.004 or later, available via
@url{http://www.perl.com/CPAN/, @code{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
@command{makeinfo} version 4.7 or later installed, and if not some of
the @HTML{} manuals will be linked to @acronym{CRAN}.  (Version 4.6 is
known to create incorrect @HTML{} files.)

@cindex Vignettes
The typeset documentation and building vignettes needs @command{tex} and
@command{latex}, or @command{pdftex} and @command{pdflatex}.

If you want to build from the R Subversion repository you need Perl,
@command{makeinfo} and @command{pdflatex}.
@cindex Subversion


@node Useful libraries and programs, Linear algebra, Essential programs, Essential and useful other programs under Unix
@section Useful libraries and programs

The use of multi-byte characters, conversion between encodings
(including for translated messages) and the @R{} @code{iconv} function
depend on having the system @code{iconv} function: this is part of
recent versions of @code{glibc} and many Unixes.  You can also install
@acronym{GNU} @code{libiconv} (which is not the same as that in
@code{glibc}), possibly as a plug-in replacement: see
@url{http://www.gnu.org/software/libiconv/,
@code{www.gnu.org/software/libiconv}}.  Note that the @R{} usage
requires @code{iconv} to be able to translate between @code{"latin1"}
and @code{"UTF-8"}, to recognize @code{""} as the current encoding and
to translate to and from the Unicode wide-character formats
@code{"UCS-[24][BL]E"} -- this is not true of most commercial Unixes.

The ability to use translated messages makes use of @code{gettext} and
most likely needs @acronym{GNU} @code{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 @code{gettext} is found.

The bitmapped graphics devices @code{jpeg()} and @code{png()} need the
appropriate headers and libraries installed: @code{jpeg} (version 6b or
later) or @code{libpng} (version 1.2.3 or later) and @code{zlib}
(version 1.1.3 or later) respectively.

The @code{bitmap} and @code{dev2bitmap} devices and also
@code{embedFonts()} use ghostscript (@url{http://www.cs.wisc.edu/~ghost,
@code{www.cs.wisc.edu/~ghost}}).

If you have them installed (including the appropriate headers and of
recent enough versions), @code{zlib}, @code{libbz2} and PCRE will be
used if specified by @option{--with-system-zlib},
@option{--with-system-bzlib} or @option{--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 @code{zlib} 1.2.3 in the @R{} sources has
enhancements to work with large file systems on 32-bit platforms.

@menu
* Tcl/Tk::                      
* Java support::                
@end menu

@node Tcl/Tk, Java support, Useful libraries and programs, Useful libraries and programs
@subsection Tcl/Tk

The @pkg{tcltk} package needs Tcl/Tk installed: the sources are
available at @url{http://www.tcl.tk/, @code{www.tcl.tk}}.  To specify
the locations of the Tcl/Tk files you may need the configuration options

@table @option
@item --with-tcltk
use Tcl/Tk, or specify its library directory
@item --with-tcl-config=@var{TCL_CONFIG}
specify location of @file{tclConfig.sh}
@item --with-tk-config=@var{TK_CONFIG}
specify location of @file{tkConfig.sh}
@end table

@noindent
or use the configure variables @code{TCLTK_LIBS} and
@code{TCLTK_CPPFLAGS} to specify the flags needed for linking against
the Tcl and Tk libraries and for finding the @file{tcl.h} and
@file{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.

@node Java support,  , Tcl/Tk, Useful libraries and programs
@subsection Java support

@command{configure} looks for Java support on the host system, and if it
finds it sets some settings which are useful for Java-using packages.
@env{JAVA_HOME} can be set during the @command{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
@env{R_JAVA_LD_LIBRARY_PATH} in file @file{R_HOME/etc/ldpaths} (or a
sub-architecture-specific version).  A typical setting for Sun Java is

@example
/usr/java/jdk1.5.0_06/jre/lib/amd64/server:/usr/java/jdk1.5.0_06/jre/lib/amd64
@end example

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
@env{R_JAVA_LD_LIBRARY_PATH} (e.g. in @file{~/.Renviron}), or using
@file{/etc/ld.so.conf} to specify the Java runtime library paths to the
system.

Other settings are recorded in @file{etc/Makeconf} (or a
sub-architecture-specific version), e.g.

@example
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
@end example

@noindent
where @samp{JAVA_LIBS} contains flags necessary to link JNI programs.


@node Linear algebra,  , Useful libraries and programs, Essential and useful other programs under Unix
@section Linear algebra
@cindex BLAS library

@menu
* BLAS::                        
* LAPACK::                      
* Caveats::                     
@end menu

@node BLAS, LAPACK, Linear algebra, Linear algebra
@subsection BLAS

The linear algebra routines in @R{} can make use of enhanced BLAS (Basic
Linear Algebra Subprograms, @url{http://www.netlib.org/blas/faq.html,
@code{www.netlib.org/blas/faq.html}}) routines.  However, as from @R{}
2.4.0@footnote{Earlier versions of @R{} searched for external BLASes,
but this caused frequent difficulties.} 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 @emph{via} a value for the
configuration option @option{--with-blas} and not to use an external
BLAS library by @option{--without-blas} (the default).  If
@option{--with-blas} is given with no, its value is taken from the
environment variable @env{BLAS_LIBS}, set for example in
@file{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 @code{-l}, so 

@example
--with-blas="foo"
@end example

@noindent
is an instruction to link against @code{-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 @footnote{he generic BLAS supplied with Fedora Core 3 and 4
Extras is missing @code{drotm}, @code{drotmg} and @code{zdrot}} double
precision and double complex routines@footnote{unless FORTRAN double
complex is not supported on the platform}, as well as @code{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 (@code{libsunperf} on
Sun Sparc@footnote{Using the SunPro aka Forte aka Sun ONE @command{cc}
and @command{f95} compilers}, @code{libessl} on IBM, @code{vecLib} on
Mac OS X).  The correct incantation for these is usually found
@emph{via} @option{--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 @code{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 @option{--enable-BLAS-shlib} is @strong{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 @pkg{quantreg} will need
to be re-installed.


@menu
* ATLAS::                       
* ACML::                        
* Goto BLAS::                   
* MKL::                         
* Shared BLAS::                 
@end menu

@node ATLAS, ACML, BLAS, BLAS
@subsubsection ATLAS

ATLAS (@url{http://math-atlas.sourceforge.net/,
@code{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 @code{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

@example
--with-blas="-lf77blas -latlas"
@end example

@noindent
if the libraries are in the library path, otherwise by

@example
--with-blas="-L/path/to/ATLAS/libs -lf77blas -latlas"
@end example

@noindent
For systems with multiple processors it is possible to use a
multi-threaded version of ATLAS, by specifying

@example
--with-blas="-lptf77blas -lpthread -latlas"
@end example

Users of Fedora Core 4 Extras may want to use
@example
--with-blas="-lf77blas -latlas -llapack_atlas" --with-lapack
@end example

@noindent
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 @cputype{x86_64}) as it is not by default built with
position-independent code.

An ATLAS `tuned' BLAS can also be used on Windows: see @pxref{Getting
the source files} when building from source, and
@url{http://CRAN.R-project.org/bin/windows/rw-FAQ.html, R Windows
@acronym{FAQ}} for adding pre-compiled support to binary versions.

@node ACML, Goto BLAS, ATLAS, BLAS
@subsubsection ACML

For @cputype{x86_64} and @cputype{ix86} processors under Linux there is
the AMD Core Math Library (ACML) @url{http://www.amd.com/acml,
@code{www.amd.com/acml}}.  For the @command{gcc} version we could use

@example
--with-blas="-lacml"
@end example

@noindent
if the appropriate library directory (such as
@file{/opt/acml3.5.0/gfortran64/lib}) is in the @env{LD_LIBRRARY_PATH}.  For
other compilers, see the ACML documentation.  Although the documentation
is unclear, 32-bit versions of ACML do run on other @cputype{ia32} chips
such as AthlonMP and P4.  There is a multithreaded version of ACML
available for @command{gfortran} which makes use of @code{libgomp} (and
the latter must be installed).

See @pxref{Shared BLAS} for an alternative way to use ACML.

ACML can be used on Windows when building from source.

@node Goto BLAS, MKL, ACML, BLAS
@subsubsection Goto BLAS

Another tuned BLAS which is available for some processors@footnote{}
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 @emph{academic use only} (after
registering) it can be obtained via
@url{http://www.tacc.utexas.edu/resources/software/software.php,
@code{www.tacc.utexas.edu/resources/software/software.php}}.  Once this
is built and installed, it can be used by configuring with

@example
--with-blas="-lgoto"
@end example

@noindent
It has been reported that on some RedHat-based Linux systems it is
necessary to set @code{GOTO_NUM_THREADS=1} or @code{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 @pxref{Shared BLAS} for an alternative way to use the latest
versions of the Goto BLAS.


@node MKL, Shared BLAS, Goto BLAS, BLAS
@subsubsection Intel MKL

For Intel processors under Linux, Intel's Math Kernel Library
(@url{http://www.intel.com/software/products/mkl/,
@code{www.intel.com/@/software/@/products/@/mkl}}) can be used
by

@example
--with-blas="-lmkl -lguide -lpthread"
@end example

@noindent
This is multi-threaded, but the number of threads defaults to 1 (and can
be increased by setting @code{OMP_NUM_THREADS}).
(Thanks to Andy Liaw for the information.)


@node Shared BLAS,  , MKL, BLAS
@subsubsection Shared BLAS

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 @code{libRblas} stored in @file{@var{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 @option{--enable-BLAS-shlib}, and it can always be disabled via
@option{--disable-BLAS-shlib}.

This has both advantages and disadvantages.

@itemize
@item
It saves space by having only a single copy of the BLAS routines, which
is helpful if there is an external static BLAS such as is standard for
ATLAS.

@item
There may be performance disadvantages in using a shared BLAS.  Probably
the most likely is when @R{}'s internal BLAS is used and @R{} is
@emph{not} built as a shared library, when it is possible to build the
BLAS into @file{R.bin} without using position-independent code.
However, experiments showed that in many cases using a shared BLAS was
as fast, provided high levels (e.g., @option{-O3}) of compiler
optimization are used.

@item
It is easy to change the BLAS without making to re-install @R{} and all
the add-on packages, since all references to the BLAS go through
@code{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 @file{etc/ldpaths}.
@end itemize

Another option to change the BLAS in use is to symlink a dynamic BLAS
library (such as ACML or Goto's) to @file{@var{R_HOME}/lib/libRblas.so}.
For example, just

@example
mv @var{R_HOME}/lib/libRblas.so @var{R_HOME}/lib/libRblas.so.keep
ln -s /opt/acml3.5.0/gfortran64_mp/lib/libacml.so @var{R_HOME}/lib/libRblas.so
@end example

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 @file{lib} directory is in the run-time
library path).


@node LAPACK, Caveats, BLAS, Linear algebra
@subsection LAPACK

@cindex LAPACK library
Provision is made for using an external LAPACK library, principally to
cope with BLAS libraries which contain a copy of LAPACK (such as
@code{libsunperf} on Solaris, @code{vecLib} on Mac OS X and ACML on
@cputype{ix86}/@cputype{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
@strong{not} recommended.  You can specify a specific LAPACK library or
a search for a generic library by the configuration option
@option{--with-lapack}.  The default for @option{--with-lapack} is to
check the BLAS library and then look for an external library
@code{-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

@example
--with-lapack="-L/path/to/libs -llapack -lcblas"
@end example

@noindent
since the ATLAS subset of LAPACK depends on @code{libcblas}.  A value
for @option{--with-lapack} can be set @emph{via} the environment variable
@env{LAPACK_LIBS}, but this will only be used if @option{--with-lapack}
is specified (as the default value is @code{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 @emph{via} @option{--with-lapack}.

Intel's Math Kernel Library suppies a full LAPACK which can be used via
@example
--with-lapack="-L/path/to/libs -lmkl_lapack64"
@end example

@noindent
or @samp{-lmkl_lapack32}: library @code{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 @option{--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 @code{DGEEV} and @code{DGESDD} have
resulted in error messages such as

@example
DGEBRD gave error code -10
@end example

@noindent
(seen with the Debian @code{-llapack} which was current in late 2002,
Fedora Core 4 Extras @code{-llapack} in September 2005 and 64-bit
@code{libsunperf} in Forte 7).  Other potential problems are incomplete
versions of the libraries: for example @code{libsunperf} from Sun Forte
6.x was missing the entry point for @code{DLANGE} and @code{vecLib} has
omitted the BLAS routine @code{LSAME}.  For problems compiling LAPACK
using recent versions of @code{gcc} on @cputype{ix86} Linux, see
@ref{New platforms}: these problems have surfaced in Fedora Core 3's
distribution, for example.

Please @strong{do} bear in mind that using @option{--with-lapack} is
`definitely @strong{not} recommended': it is provided @strong{only}
because it is necessary on some platforms.

@node Caveats,  , LAPACK, Linear algebra
@subsection Caveats

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 @option{-dalign}
is needed so @code{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 @command{gfortran}, @pxref{Using gfortran}.

@node Configuration on Unix, Platform notes, Essential and useful other programs under Unix, Top
@appendix Configuration on Unix

@menu
* Configuration options::       
* Internationalization support::  
* Configuration variables::     
* Using make::                  
* Using FORTRAN::               
* Compile and load flags::      
@end menu

@node Configuration options, Internationalization support, Configuration on Unix, Configuration on Unix
@section Configuration options

@command{configure} has many options: running

@example
./configure --help
@end example

@noindent
will give a list.  Probably the most important ones not covered
elsewhere are (defaults in brackets)

@table @option
@item --with-x
use the X Window System [yes]
@item --x-includes=@var{DIR}
X include files are in @var{DIR}
@item --x-libraries=@var{DIR}
X library files are in @var{DIR}
@item --with-readline
use readline library (if available) [yes]
@item --enable-R-profiling
attempt to compile support for @code{Rprof()} [yes]
@item --enable-R-shlib
build @R{} as a shared/dynamic library [no]
@item --enable-BLAS-shlib
build the BLAS as a shared/dynamic library [no]
@end table

@noindent
You can use @option{--without-foo} or @option{--disable-foo} for the
negatives.

You will want to use @option{--disable-R-profiling} if you are building
a profiled executable of @R{} (e.g.@: with @samp{-pg)}.

Flag @option{--enable-R-shlib} causes the make process to build @R{} as
a dynamic (shared) library, typically called @file{libR.so}, and link
the main @R{} executable @file{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
performance@footnote{We have measured 15--20% on i686 Linux and around
10% on @cputype{x86_64} Linux.} 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
@option{--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
@code{make clean} or even @code{make distclean} before doing so.


@node Internationalization support, Configuration variables, Configuration options, Configuration on Unix
@section Internationalization support

@R{} can be compiled with support for multi-byte character sets
(@acronym{MBCS}), in particular for UTF-8 locales (which are usually
identified by suffix @samp{.utf8}, something like
@samp{en_GB.utf8}@footnote{AIX has to be different: it has
@samp{EN_US.UTF-8}!}.  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 @command{configure} time
(unless disabled with @option{--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
@command{iconv} with a rich enough functionality.  If enough of these
are found, @code{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
characters@footnote{You may have to set this with @code{luit}, but it
should be the default in a window manager session started in UTF-8.}.
If run in a single-byte locale, @R{} behaves almost exactly as if it was
configured with @option{--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 @code{gettext} unless
disabled by the configure option @option{--disable-nls} or the
underlying OS has insufficiently standard C functions to support it.
The @code{configure} report will show @code{NLS} as one of the 
`Additional capabilities' if support has been compiled in, and running
in an English locale (but not the @code{C} locale) will include

@example
  Natural language support but running in an English locale
@end example

@noindent
in the greeting on starting R.


@node Configuration variables, Using make, Internationalization support, Configuration on Unix
@section Configuration variables

@findex configure
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
@file{config.site} (which documents all the variables you might want to
set) or on the command line as

@example
./configure @var{VAR}=@var{value}
@end example

@noindent
If you are building in a directory different from the sources, there can
be copies of @file{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 @env{CONFIG_SITE} to the location of
the file.

These variables are @emph{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 @code{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 @file{config.cache}, and it
is a good idea to remove that file (if it exists) before re-configuring.
Note that caching is turned @emph{off} by default: use the command line
option @option{--config-cache} (or @option{-C}) to enable caching.

@menu
* Setting paper size::          
* Setting the browser::         
* Compilation flags::           
* Making manuals::              
@end menu

@node Setting paper size, Setting the browser, Configuration variables, Configuration variables
@subsection Setting paper size
One common variable to change is @env{R_PAPERSIZE}, which defaults to
@samp{a4}, not @samp{letter}.  (Valid values are @samp{a4},
@samp{letter}, @samp{legal} and @samp{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 @samp{a4} if @env{R_PAPERSIZE}
is unset.  (If the (Debian Linux) program @command{paperconf} is found
or the environment variable @env{PAPERSIZE} is set, these are used to
produce the default.)

@node Setting the browser, Compilation flags, Setting paper size, Configuration variables
@subsection Setting the browser

Another precious variable is @env{R_BROWSER}, the default browser, which
should take a value of an executable in the user's path or specify
a full path.

@node Compilation flags, Making manuals, Setting the browser, Configuration variables
@subsection Compilation flags

If you have libraries and header files, e.g., for @acronym{GNU}
readline, in non-system directories, use the variables @code{LDFLAGS}
(for libraries, using @samp{-L} flags to be passed to the linker) and
@code{CPPFLAGS} (for header files, using @samp{-I} flags to be passed to
the C/C++ preprocessors), respectively, to specify these locations.
These default to @samp{-L/usr/local/lib} (@code{LDFLAGS},
@samp{-L/usr/local/lib64} on most 64-bit Linux OSes) and
@samp{-I/usr/local/include} (@code{CPPFLAGS}) to catch the most common
cases.  If libraries are still not found, then maybe your
compiler/linker does not support re-ordering of @option{-L} and
@option{-l} flags (this has been reported to be a problem on HP-UX with
the native @command{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 @command{gcc}, having @samp{-O3} in
@code{CFLAGS} and @code{FFLAGS} produces worthwhile performance gains.
On systems using the GNU linker (especially those using @R{} as a shared
library), it is likely that including @samp{-Wl,-O1} in @code{LDFLAGS}
is worthwhile, and on upcoming systems@footnote{e.g. Fedora Core 6}
@samp{'-Wl,-O1,-Bdirect,--hash-style=both'} is recommended at
@url{http://lwn.net/Articles/192624/}

@node Making manuals,  , Compilation flags, Configuration variables
@subsection Making manuals

The default settings for making the manuals are controlled by
@env{R_RD4PDF}, @env{R_RD4DVI} and @env{R_PAPERSIZE}.



@node Using make, Using FORTRAN, Configuration variables, Configuration on Unix
@section Using make
@findex make

To compile @R{}, you will most likely find it easiest to use GNU
@command{make}.  On Solaris 2.6/7/8 in particular, you need a version of
@acronym{GNU} @command{make} different from 3.77; 3.79.1 and later work
fine, as does the Sun @command{make}.  The native @command{make} is
reported to fail on SGI Irix 6.5 and Alpha/OSF1 (aka Tru64).

To build in a separate directory you need a @command{make} that uses the
@code{VPATH} variable, for example @acronym{GNU} @command{make}, or Sun
@command{make} on Solaris 2.7/8/9 (but not earlier).

If you want to use a @command{make} by another name, for example if your
@acronym{GNU} @command{make} is called @samp{gmake}, you need to set the
variable @code{MAKE} at configure time, for example

@findex configure
@example
./configure MAKE=gmake
@end example

@node Using FORTRAN, Compile and load flags, Using make, Configuration on Unix
@section Using FORTRAN
@cindex FORTRAN

@menu
* Using gfortran::              
@end menu

To compile @R{}, you need a FORTRAN compiler.  The default
is to search for
@c F95_compilers in m4/R.m4:
@command{f95}, @command{fort}, @command{xlf95},
@command{ifort}, @command{ifc}, @command{efc}, @command{pgf95}
@command{lf95}, @command{gfortran}, @command{ftn}, @command{g95},
@c F90 compilers in m4/R.m4:
@command{f90}, @command{xlf90}, @command{pghpf}, @command{pgf90},
@command{epcf90},
@c F77 compilers in m4/R.m4:
@command{g77}, @command{f77}, @command{xlf}, @command{frt},
@command{pgf77}, @command{cf77}, @command{fort77}, @command{fl32},
@command{af77} (in that order)@footnote{On HP-UX @command{fort77} is the
@acronym{POSIX} compliant FORTRAN compiler, and comes after
@command{g77}.}, and use whichever is found first; if none is found,
@R{} cannot be compiled.
@c GCC_Fortran_compiler in m4/R.m4:
However, if @command{CC} is @command{gcc}, the matching FORTRAN compiler
(@command{g77} for @command{gcc}@tie{}3 and @code{gfortran} for
@command{gcc}@tie{}4) is used if available.

The search mechanism can be changed using the configure variable
@code{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 @env{PATH} accordingly before
running @command{configure}, or use the configure variable @code{F77} to
specify its full path.

If your FORTRAN libraries are in slightly peculiar places, you should
also look at @env{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 @code{integer} is equivalent to a C @code{int} pointer and
FORTRAN @code{double precision} is equivalent to a C @code{double}
pointer.  This is checked during the configuration process.

Some of the FORTRAN code makes use of @code{COMPLEX*16} variables, which
is a Fortran 90 extension.  This is checked for at configure
time@footnote{as well as its equivalence to the @code{Rcomplex}
structure defined in @file{R_ext/Complex.h}.}, but you may need to avoid
compiler flags@footnote{In particular, avoid @command{g77}'s
@option{-pedantic}, which gives confusing error messages.} asserting
FORTRAN 77 compliance.

@cindex BLAS library
For performance reasons@footnote{e.g., to use an optimized BLAS on
Sun/Sparc} you may want to choose a FORTRAN 90/95 compiler.

It is possible to use @command{f2c}, the FORTRAN-to-C converter
(@url{http://www.netlib.org/f2c, @code{www.netlib.org/f2c}}), via a
script.  (An example script is given in @file{scripts/f77_f2c}: this can
be customized by setting the environment variables @env{F2C},
@env{F2CLIBS}, @env{CC} and @env{CPP}.)  You may need to ensure that the
FORTRAN type @code{integer} is translated to the C type @code{int}.
Normally @file{f2c.h} contains @samp{typedef long int integer;}, which
will work on a 32-bit platform but not on a 64-bit platform.  If your
compiler is not @command{gcc} you will need to set @env{FPICFLAGS}
appropriately.


@node Using gfortran,  , Using FORTRAN, Using FORTRAN
@subsection Using gfortran

@command{gfortran} is the F95 compiler that is part of
@command{gcc}@tie{}4.@var{x}.@var{y}.

There was a problem with the version in the @command{gcc}@tie{}4.0.0
release and most pre-releases.  At least on @cputype{ix86} and
@cputype{x86_64} Linux and MacOS X the dynamic version of the FORTRAN
runtime @code{libgfortran} could not be used: if this is loaded
redirection of C @file{stdin} (which @R{} uses in many of its scripts)
becomes non-functional.  A workaround is to set the environment variable
@env{GFORTRAN_STDIN_UNIT} to @code{-1}, but versions before 10 April
2005 had another bug causing the setting to be ignored.  Both problems
have been fixed for @command{gcc}@tie{}4.0.1.  The version of
@command{gfortran} shipping with Fedora Core 4 seems to have the fixes
in place.

Some versions of @command{g95} (from @url{http://www.g95.org,
@code{www.g95.org}}) have the same problem.

On Linux @cputype{x86_64} systems there is an incompatibility in the
return conventions for double-complex functions between
@command{gfortran} and @command{g77} which results in the final example
in @code{example(eigen)} hanging or segfaulting under external BLASs
built under @command{g77}, as well as with earlier binary versions of Dr
Goto's BLAS.  This should be detected by a @command{configure} test.

@node Compile and load flags,  , Using FORTRAN, Configuration on Unix
@section Compile and load flags

A wide range of flags can be set in the file @file{config.site} or as
configure variables on the command line.  We have already mentioned

@table @code
@item CPPFLAGS
header file search directory (@option{-I}) and any other miscellaneous
options for the C and C++ preprocessors and compilers
@item LDFLAGS
path (@option{-L}), stripping (@option{-s}) and any other miscellaneous
options for the linker
@end table

@noindent
and others include

@table @code
@item CFLAGS
debugging and optimization flags, C
@item MAIN_CFLAGS
ditto, for compiling the main program
@item SHLIB_CFLAGS
for shared libraries
@item FFLAGS
debugging and optimization flags, FORTRAN
@item SAFE_FFLAGS
ditto for source files which need exact floating point behaviour
@item MAIN_FFLAGS
ditto, for compiling the main program
@item SHLIB_FFLAGS
for shared libraries
@item MAIN_LDFLAGS
additional flags for the main link
@item SHLIB_LDFLAGS
additional flags for linking the shared libraries
@item LIBnn
the primary library directory, @file{lib} or @file{lib64}
@item CPICFLAGS
special flags for compiling C code to be turned into a shared library
@item FPICFLAGS
special flags for compiling Fortran code to be turned into a shared library
@item CXXPICFLAGS
special flags for compiling C++ code to be turned into a shared library
@item FPICFLAGS
special flags for compiling Fortran 95 code to be turned into a shared library
@item DEFS
defines to be used when compiling C code in R itself
@end table

@noindent
Library paths specified as @option{-L/lib/path} in @code{LDFLAGS} are
collected together and prepended to @env{LD_LIBRARY_PATH} (or your
system's equivalent), so there should be no need for @option{-R} or
@option{-rpath} flags.

Variables such as @env{CPICFLAGS} are determined where possible by
@command{configure}.  Some systems allows two types of PIC flags, for
example @samp{-fpic} and @samp{-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 @samp{MAIN_CFLAGS=-pg}, @samp{MAIN_FFLAGS=-pg},
@samp{MAIN_LDFLAGS=-pg} on platforms where @samp{-pg} cannot be used
with position-independent code.

@strong{Beware}: it may be necessary to set @code{CFLAGS} and
@code{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 @command{configure} will select additional flags for
@code{CFLAGS}, @code{CPPFLAGS}, @code{FFLAGS}, @code{CXXFLAGS} and
@code{LIBS} in @code{R_XTRA_CFLAGS} (and so on).  These are for options
which are always required, for example to force @acronym{IEC}@tie{}60559
compliance.


@node Platform notes, Enabling search in HTML help, Configuration on Unix, Top
@appendix Platform notes

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.

@menu
* X11 issues::                  
* Linux::                       
* Mac OS X::                    
* Solaris::                     
* HP-UX::                       
* IRIX::                        
* Alpha/OSF1::                  
* Alpha/FreeBSD::               
* AIX::                         
* New platforms::               
@end menu

@node X11 issues, Linux, Platform notes, Platform notes
@section X11 issues

The @samp{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
console and sometimes remotely from an X11 session running on a Windows
machine, you may have to setup the fonts differently for the two usages.

When X11 was designed, most displays were around 75dpi, whereas today
they are of the order of 100dpi or even higher.  If you find that X11()
is reporting@footnote{for example, @code{X11 font at size 14 could not
be loaded}.} missing font sizes, especially larger ones, it is likely
that you are not using scalable fonts and have not installed the 100dpi
versions of the X11 fonts.  The names and details differ by system, but
will likely have something like Fedora Core 5's
@example
xorg-x11-fonts-75dpi
xorg-x11-fonts-100dpi
xorg-x11-fonts-truetype
xorg-x11-fonts-Type1
xorg-x11-fonts-cyrillic
@end example

@noindent
and you need to ensure that the @samp{-100dpi} versions are installed
and on the X11 font path (check via @command{xset -q}).  The
@samp{X11()} device does try to set a pointsize and not a pixel size:
laptop users may find the default setting of 12 too large (although very
frequently laptop screens are set to a fictitious dpi to appear like a
scaled-down desktop screen).

More complicated problems can occur in non-Western-European locales, so
if you are using one, the first thing to check is that things work in
the @code{C} locale.  The likely issues are a failure to find any fonts
or glyphs being rendered incorrectly (often as a pair of ASCII
characters).  X11 works by being asked for a font specification and
coming up with its idea of a close match.  For text (as distinct from
the symbols used by plotmath), the specification is the first element of
the option @code{"X11fonts"} which defaults to

@example
"-adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
@end example

If you are using a single-byte encoding, for example ISO 8859-2 in
Eastern Europe or KOI8-R in Russian, use @command{xlsfonts} to find an
appropriate family of fonts in your encoding (the last field in the
listing).  If you find none, it is likely that you need to install
further font packages, such as @samp{xorg-x11-fonts-cyrillic} shown in
the listing above.

Multi-byte encodings (most commonly UTF-8) are even more complicated.
There are few fonts in @samp{iso10646-1}, the Unicode encoding, and they
only contain a subset of the available glyphs (and are often fixed-width
designed for use in terminals).  In such locales @emph{fontsets} are
used, made up of fonts encoded in other encodings.  If the locale you
are using has an entry in the @samp{XLC_LOCALE} directory (typically
@file{/usr/X11R6/lib/X11/locale}, it is likely that all you need to do
is to pick a suitable font specification that has fonts in the encodings
specified there.  If not, you may have to get hold of a suitable locale
entry for X11.  This may mean that, for example, Japanese text can be
displayed when running in @samp{ja_JP.utf8} but not when running in
@samp{en_GB.utf8} on the same machine (although on some systems many
UTF-8 X11 locales are aliased to @samp{en_US.utf8} which covers several
character sets, e.g.@: ISO 8859-1 (Western European), JISX0208 (Kanji),
KSC5601 (Korean), GB2312 (Chinese Han) and JISX0201 (Kana)).

On some systems scalable fonts are available covering a wide range of
glyphs.  One source is TrueType fonts, and these can provide high
coverage.  Another is Type 1 fonts: the URW set of Type 1 fonts provides
standard typefaces such as Helvetica with a larger coverage of Unicode
glyphs than the standard X11 bitmaps, including Cyrillic.  These are
generally not part of the default install, and the X server may need to
be configured to use them.  They might be under the X11 @file{fonts}
directory or elsewhere, for example,

@example
/usr/share/fonts/default/Type1
/usr/share/fonts/ja/TrueType
@end example


@node Linux, Mac OS X, X11 issues, Platform notes
@section Linux
@cindex Linux

Linux is the main development platform for @R{}, so compilation from the
sources is normally straightforward with the standard compilers.

Remember that some package management systems (such as @acronym{RPM} and
deb) make a distinction between the user version of a package and the
developer version.  The latter usually has the same name but with the
extension @samp{-devel} or @samp{-dev}: you need both versions
installed.  So please check the @code{configure} output to see if the
expected features are detected: if for example @samp{readline} is
missing add the developer package.  (On most systems you will also need
@samp{ncurses} and its developer package, although these should be
dependencies of the @samp{readline} package(s).)

When @R{} has been installed from a binary distribution there are
sometimes problems with missing components such as the FORTRAN
compiler.  Searching the @samp{R-help} archives will normally reveal
what is needed.

It seems that @cputype{ix86} Linux accepts non-PIC code in shared
libraries, but this is not necessarily so on other platforms, in
particular for 64-bit CPUs such as that for AMD Opteron.  So care can be
needed with BLAS libraries and when building @R{} as a shared library to
ensure that position-independent code is used in any static libraries
(such as the Tcl/Tk libraries, @code{libpng}, @code{libjpeg} and
@code{zlib}) which might be linked against.  Fortunately these are
normally built as shared libraries with the exception of the ATLAS BLAS
libraries.

For platforms with both 64- and 32-bit support, it is likely that

@example
LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib"
@end example

@noindent
is appropriate since most (but not all) software installs its 64-bit
libraries in @file{/usr/local/lib64}.  To build a 32-bit version of @R{}
on @cputype{x86_64} with Fedora Core 5 we used

@example
CFLAGS="-m32 -O2 -g -Wall -pedantic -std=gnu99" 
CXXFLAGS="-m32 -O2 -g" 
FFLAGS="-m32 -O2 -g"
LDFLAGS="-m32 -L/usr/local/lib"
LIBnn=lib
@end example

@noindent
Fedora Core 3 also needed
@example
--x-libraries=/usr/X11R6/lib
@end example

@noindent
and in both cases various @cputype{i386} @samp{-devel} RPMs had to be
added.

64-bit versions of Linux are built with support for files > 2Gb, and
32-bit versions will be if possible unless @option{--disable-largefile}
is specified.

@R{} used to include the compiler flag @option{-mieee-fp}, but it seems
this was really an alias for the linker flag @option{-lieee}.  Neither
are needed for a modern Linux (e.g.@: using @code{glibc} 2.2/3/4) but
could conceivably be needed on an older version.  @code{glibc} 2.1
required @option{-D__NO_MATH_INLINES} to achieve
@acronym{IEC}@tie{}60059-compliance for @code{exp}, and this is included
in @code{R_XTRA_CFLAGS} if required.

Several Linux distributions have shipped unreleased versions of
@command{gcc}@tie{}4.0.0 and its FORTRAN compiler @command{gfortran}
(see the separate comments).  Some versions of @command{gcc}@tie{}4
(such as that in Fedora Core 3) produce incorrect code.  In our
experiments @command{gcc}@tie{}3.4.x always produced faster and more
reliable code.  It seems that @command{gcc}@tie{}4.0.x cannot compile
@file{src/main/plot.c} when building R as a shared library on
@cputype{ix86} unless the optimization level is changed from the default
@option{-O2} (@option{-O3} works, as does @command{gcc}@tie{}4.1.0 with
the default settings).

It has been reported that using @command{gcc}@tie{}4.0.3 on
@cputype{ppc64} needed the compiler flag @option{-mminimal-toc} to avoid
errors when linking @R{} as a shared library.

Intel compilers have been used under @cputype{ix86} and @cputype{x86_64}
Linux and @R{} contains code to set the FPU options suitably.  Brian
Ripley tried version 9.0 of the compilers for @cputype{ix86} @emph{via}

@example
CC=icc
F77=ifort
CXX=icc
ICC_LIBS=/opt/compilers/intel/cc/9.0/lib
IFC_LIBS=/opt/compilers/intel/fc/9.0/lib
LDFLAGS="-L$ICC_LIBS -L$IFC_LIBS -L/usr/local/lib"
@end example

@noindent
and adding optimization flags failed: at least @file{src/@/main/@/regex.c}
and @file{src/@/modules/@/lapack/@/dlamc.f} needed to be compiled without
optimization.  For @cputype{x86_64} he used

@example
CC=icc
CFLAGS="-g -O2 -wd188"
F77=ifort
CXX=icc
ICC_LIBS=/opt/compilers/intel/cce/9.0/lib
IFC_LIBS=/opt/compilers/intel/fce/9.0/lib
LDFLAGS="-L$ICC_LIBS -L$IFC_LIBS -L/usr/local/lib"
@end example

@noindent
@R{} will add @samp{-mp} in @code{R_XTRA_@{C,F,CXX@}FLAGS} to maintain
correct @acronym{IEC}@tie{}60559 arithmetic.  The flag @option{-wd188}
suppresses a large number of warnings about the enumeration type
@samp{Rboolean}.  Because the Intel C compiler sets @samp{__GNUC__}
without complete emulation of @command{gcc}, we suggest adding
@code{CPPFLAGS=-no-gcc}.

For some comments on building on an Itanium (@cputype{ia64}) Linux
system with @command{gcc} or the Intel compilers see
@url{http://www.nakama.ne.jp/memo/ia64_linux/,
@code{www.nakama.ne.jp/memo/ia64_linux}}.

Jennifer Lai used the Portland Group compilers on @cputype{x86_64} to
build pre-2.2.0.  Updated versions of the settings she used are

@example
PG_HOME=/usr/pgi/linux86-64/6.0
CC=pgcc
CFLAGS="-g -O2 -Kieee"
CPPFLAGS="-I$PG_HOME/include -I$PG_HOME/include/CC"
F77=pgf77
FFLAGS="-g -O2 -Kieee"
CXX=pgCC
CXXFLAGS="-g -O2 -Kieee"
FC=pgf95
FCFLAGS="-g -O2 -Kieee"
SHLIB_CXXLDFLAGS=-shared
SHLIB_LDFLAGS=-shared
LDFLAGS="-L$PG_HOME/libso -L/usr/lib64"
@end example

@noindent
Note particularly the last, which is needed to ensure that a shared
version of @code{libc} is found.  The flag @option{-Kieee} ensures strict
compilance to IEC60659.  Also,
@url{http://@/www.amd.com/@/us-en/@/assets/@/content_type/@/DownloadableAssets/@/dwamd_PGI_nov603.pdf}
suggests that @option{-pc64} may be desirable.


@node Mac OS X, Solaris, Linux, Platform notes
@section Mac OS X
@cindex Mac OS X

You can build @R{} as a Unix application on Mac OS X using the Apple
Developer Tools and @command{g77} or @command{gfortran}.  You will also
need to install an X sub-system or configure with
@option{--without-x}. The X window manager is part of the standard Mac
OS X distribution since Mac OS X version 10.3 (Panther).

For more information on how to find these tools please read the
@url{http://CRAN.R-project.org/bin/macosx/RMacOSX-FAQ.html, R for Mac
OS X @acronym{FAQ}}.

If you use the X window manager and prefer @code{Terminal.app} to
@code{xterm}, you should be aware that @R{}, like many Unix tools, uses
the existence of a @env{DISPLAY} environment variable to determine
whether an X system is running.  This affects the default graphics
device for the commmand-line version of R and the behaviour of the
@code{png} and @code{jpeg} devices.


@cindex BLAS library
@cindex LAPACK library
The @code{vecLib} library of Mac OS X >= 10.2.2 can be used @emph{via} the
(default) configuration options

@example
--with-blas="-framework vecLib" --with-lapack
@end example

@noindent
to provide higher-performance versions of the BLAS and LAPACK
routines.  Building @R{} without these options @emph{via}

@example
--without-blas --without-lapack
@end example

@noindent
used not to work with earlier versions of @command{gcc}, but can be done
with @command{gcc}@tie{}3.3 and later.


@node Solaris, HP-UX, Mac OS X, Platform notes
@section Solaris on Sparc
@cindex Solaris

@R{} has been built successfully on Sparc Solaris 8 aka Solaris 2.8 aka
SunOS 5.8 using @command{gcc}@tie{}3/@command{g77},
@command{gcc}@tie{}4/@command{gfortran} and the `Sun ONE Studio 7
Compiler Suite' (aka Forte@tie{}7), and less regularly on Solaris@tie{}9
and 10.  @acronym{GNU} @command{make} was needed prior to
Solaris@tie{}2.7 for building other than in the source tree, and is
sometimes needed to establish the correct dependencies when rebuilding.
@R{} 2.2.1-patched has been built on Solaris 7.

The Solaris versions of several of the tools needed to build @R{}
(e.g.@: @command{make}, @command{ar} and @command{ld}) are in
@file{/usr/ccs/bin}, so if using those tools ensure this is in your
path.

@command{gcc} 3.2.1 and 3.2.2 generate incorrect code on 32-bit Solaris
builds with optimization, but versions 3.2.3 and later work correctly.
(The symptom was that @code{make check} failed at the first attempt to
plot.)

If using @command{gcc}, do ensure that the compiler was compiled for the
version of Solaris in use.  (This can be ascertained from @command{gcc
-v}.)  @command{gcc} makes modified versions of some header files, and
so (for example) @command{gcc} compiled under Solaris 2.6 will not
compile @R{} under Solaris 2.7.  Also, do ensure that it was compiled
for the assembler/loader in use: if you download @command{gcc} from
@url{http://www.sunfreeware.com, @code{www.sunfreeware.com}} then you
need to download @code{binutils} too.  To avoid all these pitfalls we
strongly recommended you compile @command{gcc} from the sources
yourself.

It was reported by Mike Pacey that Sun Forte 9 requires
@samp{-xopenmp=stubs} added to @code{LDFLAGS}.

When using the SunPro compilers do @emph{not} specify @option{-fast}, as
this disables @acronym{IEEE} arithmetic and @command{make check} will
fail.  The maximal set of optimization options known to work on Sparc is

@example
-xlibmil -xO5 -dalign -xc99
@end example

@noindent
(@cputype{x86} versions do not need @samp{-dalign}, and some do not
support it.)

We have found little performance difference between @command{gcc} and
@command{cc} but considerable benefit from using a SunPro Fortran
compiler: the @command{gcc}/@command{f77} combination worked well.  For
many C++ applications Forte 7 requires @samp{-lCstd}, which the
configure script will add to @code{SHLIB_CXXLDFLAGS} if it identifies
the compiler correctly.

To compile for a 64-bit target on Sparc Solaris (which needs an
UltraSparc chip and for support to be enabled in the OS) with the Forte
7 compilers we used @option{--without-blas} and

@example
CC="cc -xarch=v9"
CFLAGS="-xO5 -xlibmil -dalign -xc99"
F77="f95 -xarch=v9"
FFLAGS="-xO5 -xlibmil -dalign"
CXX="CC -xarch=v9"
CXXFLAGS="-xO5 -xlibmil -dalign"
FC="f95 -xarch=v9"
FCFLAGS="-xO5 -xlibmil -dalign"
@end example

@noindent
in @file{config.site}.


For 64-bit compilation with @command{gcc} 3.4.x we used

@example
CC="gcc -m64"
F77="g77 -m64"
CXX="g++ -m64"
FC="gfortran -m64"
LDFLAGS="-L/usr/local/lib/sparcv9 -L/usr/local/lib"
@end example

@noindent
replacing @samp{g77} with @samp{gfortran} for @command{gcc} 4.0.x.  Note
that @file{/usr/local/lib/sparcv9} may need to be in the
@env{LD_LIBRARY_PATH} during configuration.

Solaris on Sparc CPUs need @samp{PIC} and not @samp{pic} versions of
@env{CPICFLAGS} and @env{FPICFLAGS} since the @samp{pic} version only
allows 1024 symbols on a 64-bit build (and 2048 on a 32-bit build).


@cindex BLAS library
@cindex LAPACK library

Note that using @command{f95} allows the Sun performance library
@code{libsunperf} to be selected: it may not work@footnote{recent
versions have @command{f77} as a wrapper for @command{f95}, and these do
work.} with @command{f77}, and will not with @command{g77}.
@code{libsunperf} contains both BLAS and LAPACK code, and
@option{--with-lapack} may be required if you use it.  On our test system
using @code{libsunperf} failed for 64-bit builds with both Forte 6U1 and
7, albeit in different ways.  Our experience has been that ATLAS's BLAS
is faster than @code{libsunperf}, especially for complex numbers.

Some care is needed to ensure that libraries found by
@command{configure} are compatible with the @R{} executable and modules, as
the testing process will not detect many of the possible problems.  For
32-bit builds under @command{cc} the flag @option{-dalign} is needed for
some of the Sun libraries: fortunately the equivalent flag for
@command{gcc}, @option{-mno-unaligned-doubles}, is the default.  In
theory, libraries such as @code{libpng}, @code{libjpeg}, @code{zlib} and
the ATLAS libraries need to be built with a @code{pic} or @code{PIC}
flag, which could be a problem if static libraries are used.  In
practice this seems to give little problem for 32-bit builds, especially
as @cputype{ix86} Linux accepts non-PIC code in shared libraries.

For a 64-bit build, 64-bit libraries must be used.  As the configuration
process by default sets @code{LDFLAGS} to @samp{-L/usr/local/lib}, you
may need to set it to avoid finding 32-bit addons (as in the
@command{gcc -m64} example above).  It is possible to build Tcl/Tk as
64-bit libraries with the configure option @command{--enable-64bit}, but
only with the Forte compiler (and not with @command{gcc}) as of
Tcl/Tk@tie{}8.4.5.


@node HP-UX, IRIX, Solaris, Platform notes
@section HP-UX
@cindex HP-UX

The reports on HP-UX here predate @R{} 2.0.0.

@R{} has been built successfully on HP-UX 10.2 and HP-UX 11.0 using both
native compilers and @command{gcc}.  However, 10.2 has not been tested
since @R{} 1.4.0.  By default, @R{} is configured to use @command{gcc} and
@command{g77} on HP-UX (if available).  Some installations of
@command{g77} only install a static version of the @command{g2c} library
that cannot be linked into a shared library since its files have not
been compiled with the appropriate flag for producing position
independent code (@acronym{PIC}).  This will result in @command{make}
failing with a linker error similar to

@example
ld: CODE_ONE_SYM fixup to non-code subspace in file foo.o -
shared library must be position independent. Use +z or +Z to recompile.
@end example

@noindent
(@option{+z} and @option{+Z} are the @acronym{PIC} flags for the native
compiler @command{cc}.)  If this is the case you either need to modify
your @command{g77} installation or configure with

@example
F77=fort77
@end example

@noindent
to specify use of the native @acronym{POSIX}-compliant FORTRAN 77
compiler.

You may find that @command{configure} detects other libraries that R
needs to use as shared libraries but are only available as static
libraries.  If you cannot install shared versions you will need to tell
@command{configure} not to use these libraries, or make sure they are
not in the library path.  The symptom will be the linker error shown in
the last paragraph.  Static libraries that might be found and would
cause problems are

@example
BLAS                   @r{use @option{--without-blas}}
Tcl/Tk                 @r{use @option{--without-tcltk}}
libpng                 @r{use @option{--without-libpng}}
jpeg                   @r{use @option{--without-jpeglib}}
zlib                   @r{use @option{--without-system-zlib}}
@end example

@noindent
and @code{bzip2} and @code{pcre} are problematic when building
@file{libR.so}, only.  These can be avoided by
@option{--without-system-bzlib} and @option{--without-system-pcre}
respectively, but these are the defaults.

Some versions of @command{gcc} may contain what appears to be a bug at
the @option{-O2} optimization level that causes

@example
> 2 %/% 2
[1] 1
> 1:2 %/% 2
[1] 0 0     # wrong!!
@end example

@noindent
which will cause @command{make check} to fail.  If this is the case, you
should use @code{CFLAGS} to specify @option{-O} as the optimization
level to use.

Some systems running HP-UX 11.0 may have a @command{gcc} that was
installed under HP-UX 10.2.  Between versions 10.2 and 11.0 HP-UX
changed its support functions for @acronym{IEEE} arithmetic from the
recommended functions of the @acronym{IEEE} standard to the ones
specified in the C9x draft standard.  In particular, this means that
@code{finite} has been replaced by @code{isfinite}.  A @command{gcc}
configured for HP-UX 10.2 run on 11.0 will not find @code{isfinite}, and
as a result @command{configure} does not recognize the machine as fully
supporting @acronym{IEEE} arithmetic and so will not complete.  The best
solution is to install a properly configured @command{gcc}.  An
alternative work-around is to add @option{-DIEEE_754} to the
@code{CFLAGS} variable.

You can configure @R{} to use both the native @command{cc} and
@command{fort77} with

@example
./configure CC=cc F77=fort77
@end example

@command{f90} insists on linking against a static @file{libF90.a} which
typically resides in a non-standard directory (e.g.,
@file{/opt/fortran90/lib}).  Hence, to use @command{f90} one needs to
add this directory to the linker path via the configure variable
@code{LDFLAGS} (e.g., 
@command{./configure F77=f90 LDFLAGS=/opt/fortran90/lib}).


@node IRIX, Alpha/OSF1, HP-UX, Platform notes
@section IRIX
@cindex IRIX

@R{} 2.1.0 has been successfully built on IRIX64 6.5 using both
@command{gcc} and the native (MipsPro 7.4) compiler. However, neither
version has passed @command{make check} due to a problem with time
zones (see below).  A 64-bit executable has not been successfully
built.

It appears that some (but not all) versions of IRIX have broken
wide-character header files and so may need @option{--disable-mbcs}.

To build @R{} with @command{gcc} use something like the following
configuration flags

@example
CPPFLAGS="-I/usr/freeware/include" 
LDFLAGS="-L/usr/freeware/lib32"
@end example

To build the Tcl/Tk package you will most likely need to add

@example
--with-tclconfig=/usr/freeware/lib/tclConfig.sh
--with-tkconfig=/usr/freeware/lib/tkConfig.sh
@end example

@noindent
since these configuration scripts are not on your path.

To build @R{} with the native compilers, use something like the
following configuration flags

@example
CC=cc F77=f77 CXX=CC 
CPPFLAGS="-I/usr/freeware/include" LDFLAGS="-L/usr/freeware/lib32" 
CFLAGS="-O2" FFLAGS="-O2" CXXFLAGS="-O2" 
--with-system-bzlib=yes
@end example

The MipsPro compiler will not build the @code{bzlib} library, so you must use
the external one provided by SGI as a freeware package.

After configuration, it is necessary to use @command{gmake} instead of
the native @command{make} to build @R{}.

There is a problem with the time zones on IRIX (originally reported by
George N. White III for 1.9.0) which will cause the @code{strptime}
tests to fail unless Arthur Olson's timezone data
@url{ftp://elsie.nci.nih.gov/pub/,
@code{ftp://elsie.nci.nih.gov/@/pub/}} has been installed (see also
@url{http://cspry.co.uk/computing/Indy_admin/TIMEZONE.html,
@code{cspry.co.uk/@/computing/@/Indy_admin/@/TIMEZONE.html}}) and
@code{-ltz} is added to the list of libraries (for example, in
environment variable @env{LIBS}).

The flag @option{-OPT:IEEE_NaN_inf=ON} is added for the native
compilers.


@node Alpha/OSF1, Alpha/FreeBSD, IRIX, Platform notes
@section Alpha/OSF1

@R{} has been built successfully on an Alpha running OSF1 V4.0 / V5.1
using @command{gcc}/@command{g77} and @command{cc}/@command{f77}.
Mixing @command{cc} and @command{g77} fails to configure.  The
@command{configure} option @option{--without-blas} was used since the
native blas seems not to have been built with the flags needed to
suppress @code{SIGFPE}'s.  Currently @R{} does not set a signal handler
for @code{SIGFPE} on platforms that support @acronym{IEEE} arithmetic,
so these are fatal.

At some point in the past using @command{cc} required @option{-std1} to
be set so @samp{__STDC__} was defined.  As far as we know this is no
longer needed, and @command{configure} no longer sets it, but it does
set @option{-ieee_with_inexact} for the C compiler and @option{-fpe3}
for the FORTRAN compiler (and @option{-mieee-with-inexact} and
@option{-mieee} for @command{gcc}/@command{g77}) (in the appropriate
@code{R_XTRA_*} flags).


@node Alpha/FreeBSD, AIX, Alpha/OSF1, Platform notes
@section Alpha/FreeBSD

Attempts to build @R{} on an Alpha with FreeBSD 4.3 have been only
partly successful.  Configuring with @option{-mieee} added to both
@code{CFLAGS} and @code{FFLAGS} builds successfully, but tests fail with
@code{SIGFPE}'s.  It would appear that @option{-mieee} only defers these
rather than suppressing them entirely.  Advice on how to complete this
port would be greatly appreciated.


@node AIX, New platforms, Alpha/FreeBSD, Platform notes
@section AIX
@cindex AIX

We no longer support AIX prior to 4.2, and @command{configure} will
throw an error on such systems.  On later systems, ``run time linking''
linking is used, and this corresponds to setting (when using @code{gcc}:
omit @samp{-Wl,} for the native compilers).

@example
MAIN_LDFLAGS="-Wl,-brtl -Wl,-bexpall"
SHLIB_LDFLAGS="-Wl,-G -Wl,-bexpall -Wl,-bnoentry"
@end example

@noindent
(which @command{configure} does for you by default).  (There is some
suggestion (e.g.@: by @command{libtool}) that for an @cputype{ia64}
AIX@tie{}5.x system these may not be the appropriate flags but such a
system is untested.)


The rest of this section is historical, as the default @code{*_LDFLAGS}
were changed in @R{}@tie{}2.4.0.

On AIX@tie{}4.3.3 and AIX@tie{}5.[123], it was found that the use of
``run time linking'' (as opposed to normal AIX style linking) was
required.  For this, the @R{} main program must be linked to the runtime
linker with the @option{-brtl} linker option, and shareable objects must
be enabled for runtime linking with the @option{-G} linker option.
Without these options, the AIX linker would not automatically link to
any shared object with a @file{.so} extension.  Also, the @R{} main
program would be unable to dynamically load modules (such as X11) with
the @code{dlopen} call.

When setting @code{MAIN_LDFLAGS} and @code{SHLIB_LDFLAGS} accordingly,
note that linker flags must be escaped using @samp{-Wl,} if
@command{gcc} is used for linking: use @samp{MAIN_LDFLAGS="-Wl,brtl"}
and @samp{SHLIB_LDFLAGS="-Wl,-G"} in this case.

We understand that @option{--enable-R-shlib} does not work under AIX.

Tim Hoar <thoar at cgd dot ucar dot edu> reported success building
@R{} 1.9.0 under AIX 5.1 in 64-bit mode with

@example
OBJECT_MODE=64
CC=/usr/bin/xlc_r
F77=/usr/bin/xlf_r
CXX=/usr/bin/xlC_r
LDFLAGS='-brtl'
CFLAGS='-O -qstrict'
FFLAGS='-O -qstrict'
CXXFLAGS='-O -qstrict'
@end example

@noindent
and the @code{X11()} device worked.  [His system required the
@file{Makeconf} file to be edited to replace @file{/lib/crt0.o} by
@file{/lib/crt0_64.o} in @code{R_XTRA_LIBS}, but @command{configure} now
tries to detect this.  There are no recent reports of building @R{} with
the AIX compilers, only @command{gcc}.]

Ei-ji Nakama has reported that @file{src/main/regex.c} in
@R{}@tie{}2.2.0 has to be compiled with @option{-D_LINUX_SOURCE_COMPAT}
in @code{CFLAGS} in AIX@tie{}5.x (and does not work correctly with
AIX@tie{}4.x).  We believe that the patch applied since obviates the
need for this.  He tested @R{}@tie{}2.2.1@tie{}beta on AIX@tie{}5.2.

Jagat Sheth reported being able to build @R{} 2.3.0 patched on AIX@tie{}5.2
using @command{gcc}@tie{}4.1.0 and

@example
CC=/usr/local/bin/gcc
F77=/usr/local/bin/gfortran
CXX=/usr/local/bin/g++
MAIN_LDFLAGS=-Wl,-brtl
SHLIB_LDFLAGS=-Wl,-G
CFLAGS='-g -O'
FFLAGS='-O'
CXXFLAGS='-g -O'
./configure --disable-nls
@end example
@noindent
(note it is @samp{Wl} (W ell) not @samp{W1} (W one)).

Pre-release versions of @R{} 2.3.0 have been built on AIX@tie{}5.3.
(This defines the macro @samp{SOCKLEN_T} and so earlier versions of @R{}
cannot be compiled on that version of AIX.)


@node New platforms,  , AIX, Platform notes
@section New platforms

There are a number of sources of problems when installing @R {} on a new
hardware/OS platform.  These include

@strong{Floating Point Arithmetic}: @R{} requires arithmetic compliant
with @acronym{IEC}@tie{}60559, also know as @acronym{IEEE}@tie{}754.
This mandates the use of plus and minus infinity and @code{NaN} (not a
number) as well as specific details of rounding.  Althugh almost all
current FPUs can support this, selecting such support can be a pain.
The problem is that there is no agreement on how to set the signalling
behaviour; Sun/Sparc, SGI/IRIX and @cputype{ix86} Linux require no
special action, FreeBSD requires a call to (the macro)
@code{fpsetmask(0)} and OSF1 requires that computation be done with a
@option{-ieee_with_inexact} flag etc.  On a new platform you must find
out the magic recipe and add some code to make it work.  This can often
be done via the file @file{config.site} which resides in the top level
directory.

Beware of using high levels of optimization, at least initially.  On
many compilers these reduce the degree of compliance to the
@acronym{IEEE} model.  For example, using @option{-fast} on the Solaris
SunPro compilers causes @R{}'s @code{NaN} to be set incorrectly.

@strong{Shared Libraries}: There seems to be very little agreement
across platforms on what needs to be done to build shared libraries.
there are many different combinations of flags for the compilers and
loaders.  @acronym{GNU} libtool cannot be used (yet), as it currently
does not fully support FORTRAN: one would need a shell wrapper for
this).  The technique we use is to first interrogate the X window system
about what it does (using @command{xmkmf}), and then override this in
situations where we know better (for tools from the @acronym{GNU}
Compiler Collection and/or platforms we know about).  This typically
works, but you may have to manually override the results.  Scanning the
manual entries for @command{cc} and @command{ld} usually reveals the
correct incantation.  Once you know the recipe you can modify the file
@file{config.site} (following the instructions therein) so that the
build will use these options.

It seems that @command{gcc}@tie{}3.4.x and later on @cputype{ix86} Linux
defeat attempts by the LAPACK code to avoid computations entirely in
extended-precision registers, so file @file{src/modules/lapack/dlamc.f}
may need to be compiled without optimization.  Set the configure
variable @env{SAFE_FFLAGS} to the flags to be used for this file.  If
configure detects @acronym{GNU} FORTRAN it adds flag
@option{-ffloat-store} to @env{FFLAGS}.  (Other settings are needed when
using @command{icc} on @cputype{ix86} Linux, for example.)

If you do manage to get @R{} running on a new platform please let us
know about it so we can modify the configuration procedures to include
that platform.

If you are having trouble getting @R{} to work on your platform please
feel free to use the @samp{R-devel} mailing list to ask questions.  We
have had a fair amount of practice at porting @R{} to new platforms
@enddots{}

@node Enabling search in HTML help, The Windows toolset, Platform notes, Top
@appendix Enabling search in @HTML{} help

There is a search engine available from the front page of the @HTML{}
help system, the page that is displayed by @code{help.start()}.  The
search engine is written in Java and invoked by Javascript code, so the
first thing to do is to ensure that both are enabled in your favourite
browser.  Then try it and see: with most browsers you should see

@example
Applet SearchEngine started
@end example

@noindent
displayed in the status bar.  (Internet Explorer shows @code{Applet
started}.) Then click on one of the keywords and after a short delay
(several seconds) you should see a page of search results.

If this fails you should double-check that Java is enabled in your
browser by visiting a page such as
@url{http://www.java.com/en/download/help/testvm.jsp,
@code{www.java.com/en/download/help/testvm.jsp}} (although that will
fail for earlier versions of Java such as the Microsoft JVM which do
work with R).  Java 1.1 is sufficent.

On Mozilla-based browsers the links on the results page will
become inactive if you return to it: to work around this you can open
a link in a new tab or window.

Many thanks to Marc Schwartz in tracking down many of these issues with
enabling the Java search engine.

@menu
* Java Virtual Machines on Linux ::  
* Java Virtual Machines on Unix::  
* Java Virtual Machines on Windows::  
* Java Virtual Machines on Mac OS X::  
@end menu

@node Java Virtual Machines on Linux , Java Virtual Machines on Unix, Enabling search in HTML help, Enabling search in HTML help
@section Java Virtual Machines on Linux

We are aware of problems with certain Java installations.  In
particular, Sun's Java Run-time Environment @code{j2re}@tie{}1.4.2_02 to
_05 do not work under @cputype{ix86} Linux.  Version
@code{jre}@tie{}1.5.0 is strongly recommended for Mozilla-based
browsers.

This and @code{j2re}@tie{}1.4.2_01 do work: the latter can be found in
Sun's archive at @url{http://java.sun.com/products/archive/,
@code{java.sun.com/@/products/@/archive/}}.

Other Java installations, for example those from Blackdown and IBM, have
been used.

Other useful links are for Mozilla,
@url{http://plugindoc.mozdev.org/faqs/java.html,
@code{plugindoc.mozdev.org/@/faqs/@/java.html}}
and
@url{http://www.mozilla.org/releases/mozilla1.7/installation-extras.html,
@code{www.@/mozilla.org/@/releases/@/mozilla1.7/@/installation-extras.html}},
for Konqueror @url{http://www.konqueror.org/javahowto/,
@code{www.@/konqueror.org/@/javahowto/}},
for Opera
@url{http://www.opera.com/support/search/supsearch.dml?index=459,
@code{www.opera.com/@/support/@/search/@/supsearch.dml?@/index=459}}
and for Debian GNU/Linux
@url{http://www.debian.org/doc/manuals/debian-java-faq/,
@code{www.debian.org/@/doc/@/manuals/@/debian-java-faq/}}.

Note that there appears not to be a Sun Java plugin for 64-bit browsers
on @cputype{x86_64} Linux:
(@url{http://forum.java.sun.com/thread.jspa?threadID=568127&tstart=75,
@code{forum.java.sun.com/thread.jspa?threadID=568127&tstart=75}}) but
32-bit browsers have been used on that platform, and a Blackdown Java
plugin is available (but failed when tried on FC3).


@node Java Virtual Machines on Unix, Java Virtual Machines on Windows, Java Virtual Machines on Linux , Enabling search in HTML help
@section Java Virtual Machines on Unix

We have much less experience than under Linux, but we do know that Sun's
Run-time Environment @code{j2re}@tie{}1.4.2_03 does not work under
Solaris, whereas @code{jre}@tie{}1.5.0 and @code{j2re}@tie{}1.4.2_01
(available from @url{http://java.sun.com/products/archive/,
@code{java.sun.com/products/archive}}) do.

@node Java Virtual Machines on Windows, Java Virtual Machines on Mac OS X, Java Virtual Machines on Unix, Enabling search in HTML help
@section Java Virtual Machines on Windows

We have not seen any problems on Windows provided a Java Virtual Machine
has been installed and is operational: Sun's current
@code{j2re}@tie{}1.5.0 works in Internet Explorer, Netscape@tie{}7.x,
Mozilla@tie{}1.6/7 and Mozilla FireFox on Windows XP.  Note that a
recent Windows system may not have a JVM installed at all.  For
Netscape/Mozilla/FireFox visit
@url{http://java.sun.com/getjava/manual.html,
@code{java.sun.com/getjava/manual.html}} to install a Sun JVM.  Which
(if any) JVM is enabled can be set in `Set Program Access and Defaults'
in Windows XP (SP1 or later), and which JVM is used by browser plugins
may also be controlled by the Sun Java applet in the Control Panel.

Recent versions of Internet Explorer may block the use of Java applets
and need the block removed @emph{via} the @emph{information bar}.

@node Java Virtual Machines on Mac OS X,  , Java Virtual Machines on Windows, Enabling search in HTML help
@section Java Virtual Machines on Mac OS X

The @HTML{} search engine does not work with Safari under Mac OS X, but
@code{j2re}@tie{}1.4.x may work with Mozilla, Firefox and Camino if the
Java Embedding Plugin (@url{http://javaplugin.sourceforge.net/,
@code{javaplugin.sourceforge.net}}) is used.

The Aqua GUI provides an interface to @code{help.search} that may
substitute for the Java search.

@node The Windows toolset, Function and variable index, Enabling search in HTML help, Top
@appendix The Windows toolset

If you want to build @R{} from the sources in Windows, you will need to
collect, install and test an extensive set of tools.  See
@url{http://www.murdoch-sutherland.com/Rtools/,
@code{www.murdoch-sutherland.com/Rtools}} for the current locations and
other updates to these instructions.

Some of these tools are also necessary for building add-on packages from
source.  (Most Windows users will not need to do that; see @ref{Add-on
packages} for details.)  We have found that the build process for @R{}
is quite sensitive to the choice of tools: please follow our
instructions @strong{exactly}, even to the choice of particular versions
of the tools.  The build process for add-on packages is somewhat more
forgiving, but we recommend using the exact toolset at first, and only
substituting other tools once you are familiar with the process.

@emph{This section contains a lot of prescriptive comments.  They are
here as a result of bitter experience.  Please do not report problems
to R-help unless you have followed all the prescriptions.}

You will certainly need the following items to produce a working copy
of @R{}.  See the subsections below for detailed descriptions.
@itemize
@item
The command line tools
@item
Perl
@item
The MinGW compilers
@end itemize
For building simple packages containing data or @R{} source
but no compiled code, only the first two of these are needed.

A complete build of @R{} including compiled @HTML{} help files and
PDF manuals, and producing the standalone installer 
@file{@value{RWVERSION}.exe} will also need the following:
@itemize
@item
The Microsoft @HTML{} Help Workshop
@item
@LaTeX{}
@item
The Inno Setup installer
@end itemize

Your path should include @file{.} first, then the @file{bin} directories
of the tools, Perl, MinGW, and @LaTeX{}, as well as the Help Workshop
directory.  Do not use filepaths containing spaces or on network shares
(starting @code{\\}): you can always use the short forms (found by
@code{dir /x} at the Windows command line).  It is essential that the
directory containing the command line tools comes first or second in the
path: there are typically like-named tools in other directories, and
they will @strong{not} work.  The ordering of the other directories is
less important, but if in doubt, use the order above.

Edit @file{@var{R_HOME}/src/gnuwin32/MkRules} to set the appropriate
paths as needed and to set the type(s) of help that you want built.
@strong{Beware}: @file{MkRules} contains tabs and some editors
(e.g., WinEdt) silently remove them.

Set the appropriate environment variables.
 
Our toolset contains copies of Cygwin DLLs that may conflict with other
ones on your system if both are in the path at once.  The normal
recommendation is to delete the older ones; however, at one time we
found our tools did not work with a newer version of the Cygwin DLLs, so
it is safest not to have any other version of the Cygwin DLLs in your
path.

@menu
* The command line tools::      
* Perl::                        
* The MinGW compilers::         
* The Microsoft HTML Help Workshop::  
* LaTeX::                       
* The Inno Setup installer::    
@end menu

@node The command line tools, Perl, The Windows toolset, The Windows toolset
@section The command line tools

You will need suitable versions of at least @code{basename}, @code{cat},
@code{cmp}, @code{comm}, @code{cp}, @code{cut}, @code{diff}, @code{echo},
@code{egrep}, @code{expr}, @code{find}, @code{gawk}, @code{grep},
@code{gzip}, @code{head}, @code{ls}, @code{make}, @code{makeinfo},
@code{mkdir}, @code{mv}, @code{rm}, @code{sed}, @code{sh}, @code{sort},
@code{texindex} and @code{touch}; we use those from the Cygwin
distribution (@url{http://www.cygwin.com, @code{www.cygwin.com}}) or
compiled from the sources.  You will also need @code{zip} and
@code{unzip} from the Info-ZIP project (@url{http://www.info-zip.org,
@code{www.info-zip.org}}).  We have packaged a set of all of these tools
at @url{http://www.murdoch-sutherland.com/Rtools/tools.zip,
@code{www.murdoch-sutherland.com/@/Rtools/@/tools.zip}}.

@strong{Beware}: `Native' ports of make are @strong{not} suitable
(including that at the mingw site).  There were also problems with
several earlier versions of the cygwin tools and DLL.  To avoid
frustration, please use our tool set, and make sure it is at the front
of your path (including before the Windows system directories).  If you
are using a Windows shell, type @code{PATH} at the prompt to find out.

@node Perl, The MinGW compilers, The command line tools, The Windows toolset
@section Perl

You will need the Windows port of @code{perl5}.  A package containing
this is available from
@url{http://www.activestate.com/Products/ActivePerl/,
@code{www.activestate.com/@/Products/@/ActivePerl}}.

@strong{Beware}: you do need the @emph{Windows} port and not the Cygwin one.

@node The MinGW compilers, The Microsoft HTML Help Workshop, Perl, The Windows toolset
@section The MinGW compilers

You need a recent version of the MinGW port of @command{gcc} from
@url{http://www.mingw.org, @code{www.mingw.org}}.  See the notes on
@url{http://www.murdoch-sutherland.com/Rtools/,
@code{www.murdoch-sutherland.com/@/Rtools}} for updates.

There may be an installer in the `Proposed' section, which can be used
if it gives the @samp{Candidate} compilers (@code{gcc-3.4.5}).  (If
using this, select the @samp{Candidate} package and add the @code{g++}
and @code{g77} compilers to the @samp{MinGW base tools}: components will
be downloaded from Sourceforge and unpacked.)

An alternative is to download the components individually, currently

@example
mingw-runtime-3.10.tar.gz
w32api-3.7.tar.gz
binutils-2.16.91-20060119-1.tar.gz
gcc-core-3.4.5-20060117-1.tar.gz
gcc-g++-3.4.5-20060117-1.tar.gz
gcc-g77-3.4.5-20060117-1.tar.gz
@end example

@noindent
and unpack these into the same directory (using @command{tar zxf
tarball_name}).  Note that @code{mingw-runtime-3.10.tar.gz} or later is
required to build @R{}, @code{gcc-g77-3.4.4} or later to build some
contributed packages, and @code{gcc-3.4.5} is needed to get a correct
build of @R{} itself.

@node The Microsoft HTML Help Workshop, LaTeX, The MinGW compilers, The Windows toolset
@section The Microsoft @HTML{} Help Workshop

To make compiled html (@file{.chm}) files you will need the Microsoft
@HTML{} Help Workshop, currently available for download at
@url{http://msdn.microsoft.com/library/en-us/htmlhelp/html/hwmicrosofthtmlhelpdownloads.asp,
@code{msdn.microsoft.com/@/library/@/en-us/@/htmlhelp/@/html/@/hwmicrosofthtmlhelpdownloads.asp}}
and @url{http://www.microsoft.com/office/ork/xp/appndx/appa06.htm,
@code{www.microsoft.com/@/office/@/ork/@/xp/@/appndx/@/appa06.htm}}.

You may need this on the same drive as the other tools.  (Although we
regularly use it on a different, problems have been reported in the
past.)

To skip building compiled html help, set @code{WINHELP=NO} in @file{MkRules}.
In this case the Help Workshop will not be needed.

@node LaTeX, The Inno Setup installer, The Microsoft HTML Help Workshop, The Windows toolset
@section @LaTeX{}

The @samp{MiKTeX} (@url{http://www.miktex.org, @code{www.miktex.org}})
distribution of @LaTeX{} includes a suitable port of @code{pdftex}, as
does the @samp{ProText} (@url{http://www.tug.org/protext/,
@code{www.tug.org/@/protext}}) enhanced version.  We have also used the
@samp{fptex} distribution (available from any CTAN node such as
@url{http://www.ctan.org/tex-archive/systems/windows/fptex/,
@code{www.ctan.org/@/tex-archive/@/systems/@/windows/@/fptex}} and as part of
TexLive 2005 (@url{http://www.tug.org/texlive/,
@code{www.tug.org/@/texlive}})).  Another actively-maintained version is
available from @url{http://www.fsci.fuk.kindai.ac.jp/kakuto/win32-ptex/,
@code{www.fsci.fuk.kindai.ac.jp/@/kakuto/@/win32-ptex}}.

Please read @ref{Making the manuals} about how to make @file{refman.pdf}
and set the environment variables @env{R_RD4DVI} and @env{R_RD4PDF}
suitably; ensure you have the required fonts installed.

@node The Inno Setup installer,  , LaTeX, The Windows toolset
@section The Inno Setup installer

To make the installer package (@file{@value{RWVERSION}.exe}) we require
Inno Setup 5.1.5 or later from @url{http://jrsoftware.org,
@code{jrsoftware.org}}.

Edit file @file{src/gnuwin32/MkRules} and change @code{ISDIR} to the
location where Inno Setup was installed.


@node Function and variable index, Concept index, The Windows toolset, Top
@unnumbered Function and variable index

@printindex vr

@node Concept index,  , Function and variable index, Top
@unnumbered Concept index

@printindex cp

@bye

@c Local Variables: ***
@c mode: TeXinfo ***
@c End: ***
