\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::     
* Installing R under Windows::  
* Installing R under Mac OS X::  
* Add-on packages::             
* Essential and useful other programs::  
* Configuration on Unix::       
* Enabling search in HTML help::  
* New platforms::               
* Function and variable index::  
* Concept index::               
@end menu

@node Obtaining R, Installing R under Unix, 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''.  See the file
@file{RESOURCES} in the R distribution for information on
@acronym{CRAN}.

@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}.tgz} file, and unpack it with

@smallexample
tar xvfz R-@var{x}.@var{y}.@var{z}.tgz
@end smallexample

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

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

The pathname of the directory into which the sources are unpacked should
not contain spaces, as @code{make} (specifically GNU 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}.tgz-split.*} files and paste them
together at the destination with (Unix)

@smallexample
cat R-@var{x}.@var{y}.@var{z}-split.* > R-@var{x}.@var{y}.@var{z}.tgz
@end smallexample

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

@c @cindex Patch files
@c Finally, for patch releases (@samp{@var{x}.@var{y}.@var{z}} with @var{z}
@c != 0), a patch against the preceding release is made available in
@c @file{R-@var{x}.@var{y}.@var{@{z-1@}}-@var{x}.@var{y}.@var{z}.diff.gz}
@c (e.g., @file{R-1.2.2-1.2.3.diff.gz}), which is generally a much smaller
@c file that the @file{.tgz} files.  Such a file can be applied to the
@c sources of the previous version by changing to the top directory of it
@c and

@c @smallexample
@c gzip -dc /path/to/it/R-@var{x}.@var{y}.@var{@{z-1@}}-@var{x}.@var{y}.@var{z}.diff.gz | patch -E -p1
@c @end smallexample

@c @noindent
@c Beware that this does not necessarily work if the older sources have
@c been modified (e.g., by building in their directories).

@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.
@c rsync.  The development version is also available by
@c anonymous CVS from @uref{http://anoncvs.r-project.org/}.

The tarballs are available from
@uref{ftp://ftp.stat.math.ethz.ch/pub/Software/R/}.  Download either
@samp{R-patched.tar.gz} or @samp{R-devel.tar.gz} (or the
@samp{.tar.bz2} versions) and unpack as described in the previous
section.  

These versions do not contain the current sources for the recommended
packages, which can be obtained by @code{rsync} or downloaded from CRAN.
To use @code{rsync} to install the appropriate sources for the
recommended packages, run @command{./tools/rsync-recommended} from the
top-level of the @R{} sources.

If downloading manually from CRAN, do ensure that you have the correct
versions of the recommended packages: if the number in the file
@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}.@var{z}-patched/Recommended} for
r-patched, respectively, to directory @file{src/library/Recommended} in
the sources you have unpacked.  Normally @samp{R-patched.tar.gz} will
have the number of the last released version, and @samp{R-devel.tar.gz}
that of the next minor (@samp{@var{x}.@var{y}.0}) or major release.
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

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

@c @node Using rsync,  , Getting patched and development versions, Obtaining R
@c @section Using rsync
@c @findex rsync

@c Sources are also available via anonymous rsync.  Use

@c @smallexample
@c rsync -rC --delete rsync.r-project.org::@var{module} R
@c @end smallexample

@c @noindent
@c to create a copy of the source tree specified by @var{module} in the
@c subdirectory @file{R} of the current directory, where @var{module} can
@c be one of @samp{r-release} (current released version), @samp{r-patched}
@c (patched released version), and @samp{r-devel} (development version).
@c The rsync trees are created directly from the master CVS archive and are
@c updated hourly.  The @option{-C} option in the @command{rsync} command
@c is to cause it to skip the CVS directories.  Further information on
@c @command{rsync} is available at @uref{http://rsync.samba.org/rsync/}.

Sources are also available via @uref{https://svn.R-project.org/R/}, the
R Subversion repository.  If you have a Subversion client (see
@uref{http://subversion.tigris.org/}), you can check out and update the
current r-devel from @uref{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

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

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

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

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

@noindent
(currently, there is no ``trusted certificate'').  You can accept this
certificate permanently and will not be asked about it anymore.

The sources for the recommended packages need to be downloaded
separately, as described earlier in this section.


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

@R{} will configure and build under a number of common Unix platforms
including i386-freebsd, @var{cpu}-linux-gnu for the i386, alpha, amd64,
arm, hppa, ia64, m68k, powerpc, and sparc CPUs (see e.g.@:
@uref{http://buildd.debian.org/build.php?&pkg=r-base}),
powerpc-apple-darwin and sparc-sun-solaris, as well as probably (it is
tested less frequently on these) i386-netbsd, i386-openbsd,
i386-sun-solaris, mips-sgi-irix, alpha-dec-osf4, rs6000-ibm-aix and
hppa-hp-hpux.

@cindex Linux
@cindex Mac OS X
In addition, binary distributions are available for most common Linux
distributions, and for Mac OS X (Darwin) with and without X11.  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::                
@end menu

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

First review the essential and useful tools and libraries in
@ref{Essential and useful other programs}, and install those you want or
need.  Ensure that the environment variable @samp{TMPDIR} is either
unset 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

@smallexample
./configure
make
@end smallexample

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

Then check the built system works correctly, by

@smallexample
make check
@end smallexample

@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 you would need

@smallexample
make check FORCE=FORCE
@end smallexample

More comprehensive testing can be done by

@smallexample
make check-devel
@end smallexample

@noindent
or

@smallexample
make check-all
@end smallexample

@noindent
see @file{tests/README}.

If these commands execute successfully, the @R{} binary will be copied
to the @file{@var{R_HOME}/bin} directory.  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

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

@noindent
and so on, as described further below.  This has the advantage of always
keeping your source tree ``clean''.  (You may need 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 @acronym{HTML} and
La@TeX{} 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:

@smallexample
make vignettes
@end smallexample

@noindent
which makes the @samp{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/html/faq.html}, or
@uref{http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html} which always has
the latest version).

@node Making the manuals, Installation, Simple compilation, Installing R under Unix
@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} (which is already built for you).
@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

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

You will not be able to build the info files unless you have
@command{makeinfo} version 4.5 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{ghostscript}: they have hyperlinks that can be followed in
Acrobat Reader.  The info files are suitable for reading online with
Emacs or the standalone GNU Info.  The DVI and PDF versions will be
created using the papersize selected at configuration (default ISO a4):
this can be overridden by setting @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:
@itemize @bullet
@item @code{times}
Using standard PostScript fonts.  This works well both for on-screen
viewing and for printing, and is the default from @R{} 2.0.0.  The one
disadvantage is that the Usage and Examples sections may come out rather
wide.

@item @code{lm}
Using the @emph{Latin Modern} fonts.  These are not often installed as
part of a TeX distribution, but can obtained from
@uref{http://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 @code{cm-super}
Using type-1 versions of the Computer Modern fonts by Vladimir Volovich.
This is a large installation, obtainable from
@uref{http://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 @code{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 itemize

Both Unix and Windows installations default to @code{times}.  The choice
can be overridden by setting the environment variable @code{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,  , Making the manuals, Installing R under Unix
@section Installation
@cindex Installation

After

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

@noindent
have been completed successfully, you can install the complete @R{} tree
to your system by typing

@smallexample
make install
@end smallexample

@noindent
This will install to the following directories:

@table @file
@item @var{prefix}/bin
the front-end shell script
@item @var{prefix}/man/man1
the man page
@item @var{prefix}/lib/R
all the rest (libraries, on-line help system, @dots{})
@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
@smallexample
./configure --prefix=/where/you/want/R/to/go
@end smallexample

@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 by using

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

More precise control is available at configure time via options: see
@command{configure --help} for details.

@cindex Manuals, installing

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

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

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

@node Installing R under Windows, Installing R under Mac OS X, Installing R under Unix, 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 and XP (at
least) on Intel x86 and clones (but not on other platforms).

You do need one of those Windows versions: Windows 3.11+win32s will not
work.

Your file system must allow long file names (as is likely except
perhaps for some network-mounted systems).

Installation is @emph{via} the installers @file{@value{RWVERSION}.exe}
or @file{miniR.exe}.  Just double-click on the icon and follow the
instructions.  You can uninstall @R{} from the Control Panel.

See the @uref{http://cran.r-project.org/bin/windows/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

If you want to build this port from the sources, see the file
@file{src/gnuwin32/INSTALL} in the source distribution.  You will need
to collect, install and test an extensive set of tools: see
@uref{http://www.murdoch-sutherland.com/Rtools/} for the current locations.

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 commands window at a directory @emph{whose
path does not contain spaces}, and run something like

@smallexample
tar zxvf R-@value{VERSIONno}.tgz
cd R-@value{VERSIONno}\src\gnuwin32
make all recommended
@end smallexample

@noindent
sit back and wait (for about 15 minutes on 1GHz PIII with a fast local
disc).

For further details, including how to make the documentation and how to
cross-compile, see @file{src/gnuwin32/INSTALL}.

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

The @file{bin/macosx} 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 Mac OS X version 10.2.0 or higher.

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

See the @uref{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 @uref{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


@smallexample
tar zxvf R-@value{VERSIONno}.tgz
cd R-@value{VERSIONno}
./configure --with-blas='-framework vecLib' --with-lapack --with-aqua 
make
@end smallexample

@noindent
sit back and wait. The last option @option{--with-aqua} is needed only
if you want a Console GUI. 
The first two options are strongly recommended. 

@R{} is by default configured 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[=DIR]} or at install
time as

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

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

@node Add-on packages, Essential and useful other programs, Installing R under Mac OS X, Top
@chapter Add-on packages
@cindex Packages

@menu
* Installing packages::         
* Updating packages::           
* Removing packages::           
@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 on Unix use

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

@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: @file{.Renviron} is not read by @command{R CMD}.)

The same command works in Windows if you have the source-code package
files installed.  There are a number of options available: use @code{R
CMD INSTALL --help} to see the current list.

@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, for example

@smallexample
> options(CRAN = "http://cran.us.r-project.org/")
@end smallexample

@noindent
Then download and install package @pkg{foo} by

@smallexample
> install.packages("foo")
@end smallexample

@noindent
Unless the library is specified (argument @code{lib}) the first library
in the library search path is used.

What this does is different on Unix and Windows.  On Unix it consults
the list of available source packages on @acronym{CRAN}, downloads the
latest version of the @pkg{foo} sources, and installs it (via @code{R
CMD INSTALL}).  On Windows it looks at the list of @emph{binary}
versions of packages and downloads the latest version (if any).

On Windows @code{install.packages} can also install a binary package
from a local @file{zip} file by setting argument @code{CRAN} 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}.

@findex install.binaries
On Mac OS X @code{install.packages} works as it does on other Unix
systems, but there is an additional function @code{install.binaries}
that will download and install binary packages from @acronym{CRAN}.
These Macintosh binary package files have the extension @code{tgz}. The
Aqua GUI provides for installation of either binary or source packages,
from @acronym{CRAN} or local 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{CRAN}
option 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 @acronym{CRAN}.

An alternative way of 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 (CRAN, local archive, @dots{}). 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.  This allows @R{} to fetch
packages from several repositories and keep in sync with all of them,
instead of only one CRAN mirror, and is intended to become the default
package manager for future versions of R.


@node Removing packages,  , 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

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

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

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

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

@strong{Note}: whereas it is currently possible to install package
@emph{bundles}, one cannot remove these as such---the packages contained
in the bundle have to removed individually.

@node Essential and useful other programs, Configuration on Unix, Add-on packages, Top
@appendix Essential and useful other programs

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::  
@end menu

@node Essential programs, Useful libraries and programs, Essential and useful other programs, Essential and useful other programs
@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.

Unless you do not want to view graphs on-screen you need @samp{X11}
installed, including its headers and client libraries.  (On Fedora Core 2 Linux
this means the @samp{xorg-x11-devel} and @samp{xorg-x11-libs} RPMs, for
example.  Older Linuxen used @samp{XFree86-}.)

You will need Perl version 5.004 or later, available via
@uref{http://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.5 or later installed.

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


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

The command-line editing depends on the @code{readline} library
available from any GNU mirror: you will need a fairly recent version.

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 make use of ghostscript
(@uref{http://www.cs.wisc.edu/~ghost}).

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

@menu
* Tcl/Tk::                      
* Linear algebra::              
@end menu

@node Tcl/Tk, Linear algebra, Useful libraries and programs, Useful libraries and programs
@subsection Tcl/Tk

The @pkg{tcltk} package needs Tcl/Tk installed: the sources are
available at @uref{http://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.

Versions of Tcl/Tk from 8.3 to 8.4.7 have been used successfully: 8.0 is
no longer supported.


@node Linear algebra,  , Tcl/Tk, Useful libraries and programs
@subsection Linear algebra
@cindex BLAS library

The linear algebra routines in @R{} can make use of enhanced BLAS (Basic
Linear Algebra Subprograms, @uref{http://www.netlib.org/blas/faq.html})
routines.  Some 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) but ATLAS (@uref{http://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.  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}.  (Alternatively,
the environment variable @env{BLAS_LIBS} can be set, for example in
@file{config.site}.)

For systems with multiple processors it is possible to use a
multi-threaded version of ATLAS.  (Prior to @R{} 1.8.0 this was not
supported since @code{SIGINT} signals sent to the process and handled by
the wrong thread could result in segfaults.)  A remaining issue is that
@R{} profiling, which uses the @code{SIGPROF} signal, may cause
problems.  You may want to disable profiling if you use a multi-threaded
version of ATLAS.  You can use a multi-threaded ATLAS by specifying

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

Another tuned BLAS which is available for some processors under Linux is
by Kazushige Goto, currently available at
@uref{http://www.cs.utexas.edu/users/flame/goto/}.  Once this is is
installed, it can be used by one of

@smallexample
--with-blas=goto
--with-blas=-lgoto
@end smallexample

Multi-threaded versions of Goto's BLAS are available, so please note the
@emph{caveat} in the previous paragraph.

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

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

@noindent
with the same caveat on multi-threading.  (Thanks to Andy Liaw for the
information.)

Note that the BLAS library will be used for several add-on packages as
well as for @R{} itself.  This means that it is better to use a shared
BLAS library, as most of a static library will be compiled into the @R{}
executable and each BLAS-using package.  In any case, the BLAS library
must be usable with dynamically-loadable code: this can be a problem
with ATLAS on some platforms as it is not by default built with
position-independent code.

You will need double-precision and double-complex versions of the BLAS,
but not single-precision nor complex routines.


@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 and @code{vecLib} on Mac OS X).
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.  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

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

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

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

@smallexample
DGEBRD gave error code -10
@end smallexample

@noindent
(from the Debian @code{-llapack} which was current in late 2002).  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}.

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.

An ATLAS `tuned' BLAS can also be used on Windows: see
@file{src/gnuwin32/INSTALL} for how to enable this when building from
source, and @uref{http://cran.r-project.org/bin/windows/rw-FAQ.html, R Windows
@acronym{FAQ}} for adding pre-compiled support to binary versions.
Goto's BLAS can also be used when building from source.

Note that under Unix (but not under Windows) if @R{} is compiled
against a non-default BLAS, then all BLAS-using packages must also be.
So if @R{} is re-built after ATLAS is installed, then packages such as
@pkg{quantreg} will need to be re-installed.


@node Configuration on Unix, Enabling search in HTML help, Essential and useful other programs, Top
@appendix Configuration on Unix

@menu
* Configuration options::       
* Configuration variables::     
* Using make::                  
* Using FORTRAN::               
* Compile and load flags::      
* Building the GNOME interface::  
* Platform notes::              
@end menu

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

@command{configure} has many options: running

@smallexample
./configure --help
@end smallexample

@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
@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 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 small performance
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 a @R{} system linked with @option{--enable-R-shlib} are linked
against the dynamic library and so such packages cannot be used from a
@R{} system built in the default way.

@node Configuration variables, Using make, Configuration options, 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

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

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

@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 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 @file{/usr/local/lib} and @file{/usr/local/include} 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).

@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
GNU @command{make} different from 3.77; 3.79.1 works 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 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
GNU @command{make} is called @samp{gmake}, you need to set the variable
@code{MAKE} at configure time, for example

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

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

To compile @R{}, you need a FORTRAN compiler or @command{f2c}, the
FORTRAN-to-C converter (@uref{http://www.netlib.org/f2c}).  The default
is to search for @command{g77}, @command{f77}, @command{xlf},
@command{frt}, @command{pgf77}, @command{fl32}, @command{af77},
@command{fort77}, @command{f90}, @command{xlf90}, @command{pgf90},
@command{epcf90}, @command{f95}, @command{fort}, @command{xlf95},
@command{lf95}, @command{g95}, and @command{fc} (in that
order)@footnote{On HP-UX @command{fort77} is the @acronym{POSIX}
compliant FORTRAN compiler, and comes second in the search list.}, and
then for @command{f2c}, and use whichever is found first; if none is
found, @R{} cannot be compiled.  The search mechanism can be changed
using the configure variables @code{F77} and @code{F2C} which specify
the commands that run the FORTRAN 77 compiler and FORTRAN-to-C
converter, respectively.  If @code{F77} is given, it is used to compile
FORTRAN; otherwise, if @code{F2C} is given, f2c is used even if a
FORTRAN compiler would be be available.  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.

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.  Because
of this, f2c will not be accepted on a 64-bit platform as it produces
64-bit integers, incompatible with C's @code{int} on such platforms.

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.

If you use @command{f2c} 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.

@node Compile and load flags, Building the GNOME interface, 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 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
@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.

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.


@node Building the GNOME interface, Platform notes, Compile and load flags, Configuration on Unix
@section Building the @acronym{GNOME} interface

This interface is experimental and incomplete.  The console offers a
basic command line editing and history mechanism, along with tool and
button bars that give a point-and-click interface to some @R{} commands.
Many of the features of the console are currently stubs.

Two graphics devices have been available but are currently
unbundled. The @code{gtk()} graphics device is a port of the
@code{x11()} device to @acronym{GDK} (the GIMP Drawing Kit), and is
available from CRAN as package @pkg{gtkDevice}.  The @code{gnome()}
device uses the @acronym{GNOME} canvas, and is not currently available.

Due to its experimental nature, the @acronym{GNOME} interface for @R{}
will not be built automatically.  You must specify it by running
configure with the @option{--with-gnome} option.  For example, you might
run

@smallexample
./configure --with-gnome
@end smallexample

@noindent
but please check you have all the requirements first. You need at least
the following libraries (or later) installed

@smallexample
audiofile-0.2.1
esound-0.2.23
glib-1.2.10
gtk+-1.2.10
imlib-1.9.10
ORBit-0.5.12
gnome-libs-1.4.1.2
libxml-1.8.16
libglade-0.17
@end smallexample

@noindent
It is preferable to have a complete installation of the @acronym{GNOME}
desktop environment.  If you use Linux, then this should be provided
with your distribution.

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}.  If you use a pre-packaged version of
@acronym{GNOME} then you must have the developer versions of the above
packages in order to compile the R-GNOME interface.

The full list of @acronym{GNOME} options to configure is

@table @option
@item --with-gnome
use @acronym{GNOME}, or specify its prefix [no]
@item --with-gnome-includes=@var{DIR}
specify location of @acronym{GNOME} headers
@item --with-gnome-libs=@var{DIR}
specify location of @acronym{GNOME} libs
@item --with-libglade-config=@var{LIBGLADE_CONFIG}
specify location of @command{libglade-config}
@end table


@node Platform notes,  , Building the GNOME interface, Configuration on Unix
@section 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.

Many 32-bit systems have a means of using files > 2Gb, and most are
based on that in the Single Unix specification: see
@uref{http://ftp.sas.com/standards/large.file/x_open.20Mar96.html}.
However, this is only covered under Linux and Solaris.

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

@node Linux, Mac OS X, Platform notes, Platform notes
@subsection Linux
@cindex Linux

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

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 package containing its headers.

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 the @samp{gcc} compilers normally produce PIC code on
@samp{ix86} Linux but do not necessarily do so on 64-bit versions 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.

64-bit versions of Linux are built with support for files > 2Gb, but
32-bit versions usually are not.  This can be enabled for Linux kernels
2.4.x or later by the configure option @option{--enable-linux-lfs}: it
tests for Linux, a suitable kernel and a 32-bit @samp{long} type.
A discussion of which Linux systems support large files can be found at
@uref{http://www.suse.de/~aj/linux_lfs.html}: it has been available
since about 2001.


@node Mac OS X, Solaris, Linux, Platform notes
@subsection 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{f2c} or @command{g77}.  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
@uref{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 @code{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
configuration options

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

@noindent
to provide higher-performance versions of the BLAS and LAPACK
routines.  With @command{gcc 3.1} that appears to be the only way to
build @R{}, as the Fortran support routines in @code{libg2c} cannot be
linked into a dynamic library.  (We have had reports of success and of
failure with @command{gcc 3.3}.)


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

@R{} has been built successfully on Solaris 8 aka Solaris 2.8 aka SunOS
5.8 using @command{gcc}/@command{g77} and the SunPro @w{WorkShop 6} (aka
Forte 6) compilers and the `Sun ONE Studio 7 Compiler Suite' (aka Forte
7), and less regularly on Solaris 2.5.1, 2.6, 2.7 and 9.  GNU
@command{make} is needed prior to Solaris 2.7 for building other than in
the source tree, and perhaps even then.

The Solaris versions of several of the tools needed to build @R{}
(e.g. @command{make}, @command{ar} and @command{ld}) are in
@code{/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.1, 3.2, 3.2.3 and later work
correctly.  At least files @file{src/main/engine.c},
@file{src/main/graphics.c} and @file{src/modules/devX11.c} are affected.

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
@uref{http://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.

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 is

@smallexample
-xlibmil -xO5 -dalign
@end smallexample

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 works well.  For
many C++ applications (e.g. package @pkg{Matrix}) Forte 7 requires
@code{-lCstd}, which the configure script will add to
@code{SHLIB_CXXLDFLAGS} if it identifies the compiler correctly.

A 32-bit version of R is built without large file support and so can
only handle files up to 2Gb (unlike 64-bit versions).  According to
@samp{man lfcompile} this restriction can be removed if
@option{-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1} is added to
@samp{CFLAGS}.  (This has not been tested.)


To compile for a 64-bit target on Solaris (which needs an UltraSparc
chip and for support to be enabled in the OS) with the Forte 6 and 7
compilers we used

@smallexample
CC="cc -xarch=v9"
CFLAGS="-xO5 -xlibmil -dalign"
F77="f95 -xarch=v9"
FFLAGS="-xO5 -xlibmil -dalign"
CXX="CC -xarch=v9"
CXXFLAGS="-xO5 -xlibmil -dalign"
@end smallexample

@noindent
in @file{config.site}.


For 64-bit compilation with @command{gcc} 3.2.x and later we used

@smallexample
CC="gcc -m64"
FFLAGS="-m64 -g -O2"
CXXFLAGS="-m64 -g -O2"
LDFLAGS="-L/usr/local/lib/sparcv9 -L/usr/local/lib"
@end smallexample

Note that @samp{/usr/local/lib/sparcv9} will need to be in the
@samp{LD_LIBRARY_PATH} during configuration.


@cindex BLAS library
@cindex LAPACK library

Note that using @command{f95} allows the Sun performance library
@code{libsunperf} to be selected: it will not work with @command{f77},
nor with @command{g77}.  @code{libsunperf} contains both BLAS and LAPACK
code, and @option{--with-lapack} is recommended for 32-bit builds using
@command{f95}, but not for 64-bit builds where on our test system it
failed in 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.

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


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

@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

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

@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

@smallexample
F77=fort77
@end smallexample

@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 the linker error shown in the
last paragraph.  Static libraries that might be found and would cause
problems are

@smallexample
BLAS                   use --without-blas
Tcl/Tk                 use --without-tcltk
GNOME                  not built by default
libpng                 use --without-libpng
jpeg                   use --without-jpeglib
zlib                   use --without-zlib
@end smallexample

@noindent
and @code{bzip2} and @code{pcre} are problematic when building
@file{libR.so}, only.  These can be avoided by @option{--without-bzlib}
and @option{--without-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

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

@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

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

@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., @code{./configure F77=f90
LDFLAGS=/opt/fortran90/lib}).


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

@R{} has been built successfully on IRIX64 6.5 using
@command{gcc}/@command{f77} or @command{cc}/@command{f77} for 32-bit
executables and the native compilers for a 64-bit executable.  The
command

@smallexample
./configure CC="cc -64" F77="f77 -64" --with-tcltk=no
@end smallexample

@noindent
was used to create the 64-bit executable.  It was necessary to
explicitly omit Tcl/Tk because @command{configure} would find the 32-bit
version but not detect that is was incompatible with a 64-bit build.

A 32-bit build using @command{gcc}/@command{g77} passed @command{make
check} but failed @command{make test-all-extras} in the complex LAPACK
tests.

George N. White III reports that the @code{strptime} tests in 1.9.0 fail
on IRIX 6.5 systems prior to 6.5.22m (e.g. 6.5.19m and 6.5.21m) unless
Arthur Olson's timezone data @uref{ftp://elsie.nci.nih.gov/pub/} (see
also @uref{http://cspry.co.uk/computing/Indy_admin/TIMEZONE.html}) are
installed and @code{-ltz} is added to the list of libraries (for
example, in environment variable @env{LIBS}).


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

@R{} has been built successfully on an Alpha running OSF1 V4.0 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.


@node Alpha/FreeBSD, AIX, Alpha/OSF1, Platform notes
@subsection 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,  , Alpha/FreeBSD, Platform notes
@subsection AIX
@cindex AIX

On AIX 4.3.3 and AIX 5.1, 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.

Harald Servat Gelabert <harald at cepba dot upc dot es> reported
success building @R{} 1.7.0 under AIX 5.1 with

@smallexample
CC=xlc
F77=xlf
CXX=xlC
CFLAGS=-O3 -qstrict -qmaxmem=8192
FFLAGS=-O3 -qstrict -qmaxmem=8192
CXXFLAGS=-O2 -qmaxmem=8192
MAIN_LDFLAGS=-Wl,-brtl
SHLIB_LDFLAGS=-Wl,-G
@end smallexample

@noindent
but was unable to use the X libraries or the native BLAS (ESSL) and so
used @option{--without-x --without-blas}.

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

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

@noindent
and the @code{X11()} device worked.  His system required the
@file{Makeconf} file to be edited to replace @code{/lib/crt0.o} by
@code{/lib/crt0_64.o} in @code{R_XTRA_LIBS}, and @command{configure} now
tries to detect this.

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


@node Enabling search in HTML help, New platforms, Configuration on Unix, Top
@chapter Enabling search in HTML help

There is a search engine available from the front page of the
@acronym{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

@smallexample
Applet SearchEngine started
@end smallexample

@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
@uref{http://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.

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 1.4.2_02} to
@code{_05} do not work under Linux.  Current browsers of the Mozilla
family (including Mozilla >= 1.4, Netscape 7.1 and FireFox) are compiled
under @code{gcc 3.x} and @emph{require} the @code{ns610-gcc32} version
of the Java plugin that was introduced with @code{j2re 1.4.2}, so the
only Java version that we know to work is @code{j2re 1.4.2_01}.  Marc
Schwartz has kindly made Linux @code{i586} distributions available: see
@uref{http://www.MedAnalytics.com/INSTALL}.  They can also be found at
Sun's archive at @uref{http://java.sun.com/products/archive/}.

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

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


@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, but we do know that Sun's Run-time
Environment @code{j2re 1.4.2_03} does not work under Solaris, whereas
@code{j2re 1.4.2_01} and earlier do.  Marc Schwartz kindly made Solaris
distributions of @code{j2re 1.4.2_01} available: see

@smallexample
http://www.MedAnalytics.com/INSTALL
@end smallexample


@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
1.4.2_04} works in Internet Explorer, Netscape 7.1, Mozilla 1.6/7 and
Mozilla FireFox 0.8/0.9 on Windows XP.  Note that a recent Windows system
may not have Java installed at all.  For Netscape/Mozilla/FireFox visit
@uref{http://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.

@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, and
Sun's @code{j2re 1.4.x} is said not to work with Mozilla 1.6.

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

@node New platforms, Function and variable index, Enabling search in HTML help, Top
@appendix 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{} supports the @acronym{POSIX},
SVID and @acronym{IEEE} models for floating point arithmetic.  The
@acronym{POSIX} and SVID models provide no problems.  The @acronym{IEEE}
model however can be a pain.  The problem is that there is no agreement
on how to set the signalling behaviour; Sun/Sparc, SGI/IRIX and 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.  GNU libtool cannot be used (yet), as it currently does not
fully support FORTRAN (and will most likely never support @command{f2c}:
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 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 @samp{gcc 3.4.x} on @samp{ix86} Linux defeats attempts by
the LAPACK code to avoid computations entirely in extended-precision
registers, so file @file{src/modules/lapack/dlamc.f} may need to
compiled without optimization.  If configure detects GNU Fortran it adds
flag @option{-ffloat-store} which suffices, but it is possible that 
@file{src/modules/lapack/Makefile} will need to be edited to remove
optimization on other platforms.

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 get in touch to ask questions.  We have had a fair amount
of practice at porting @R{} to new platforms @enddots{}


@node Function and variable index, Concept index, New platforms, 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: ***
