\HeaderA{options}{Options Settings}{options}
\aliasA{.Options}{options}{.Options}
\aliasA{getOption}{options}{getOption}
\keyword{environment}{options}
\keyword{error}{options}
\keyword{print}{options}
\begin{Description}\relax
Allow the user to set and examine a variety of global \dQuote{options}
which affect the way in which \R{} computes and displays its results.
\end{Description}
\begin{Usage}
\begin{verbatim}
options(...)

getOption(x)

.Options
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{...}] any options can be defined, using \code{name = value} or
by passing a list of such tagged values.  However, only the ones
below are used in \dQuote{base \R}.
Further, \code{options('name') == options()['name']}, see the example.

\item[\code{x}] a character string holding an option name.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Invoking \code{options()} with no arguments returns a list with the
current values of the options.  Note that not all options listed below
are set initially.  To access the value of a single option, one should
use \code{getOption("width")}, e.g., rather than
\code{options("width")} which is a \emph{list} of length one.

\code{.Options} also always contains the \code{options()} list (as a
pairlist, unsorted), for S compatibility.  Assigning to it will make a
local copy and not change the original.
\end{Details}
\begin{Value}
For \code{getOption}, the current value set for option \code{x}, or
\code{NULL} if the option is unset.

For \code{options()}, a list of all set options sorted by name.  For
\code{options(name)}, a list of length one containing the set value,
or \code{NULL} if it is unset.  For uses setting one or more options,
a list with the previous values of the options changed (returned
invisibly).
\end{Value}
\begin{Section}{Options used in base \R}
\describe{
\item[\code{add.smooth}:] typically logical, defaulting to
\code{TRUE}.  Could also be set to an integer for specifying how
many (simulated) smooths should be added.  This is currently only
used by \code{\LinkA{plot.lm}{plot.lm}}.

\item[\code{check.bounds}:] logical, defaulting to \code{FALSE}.  If
true, a \LinkA{warning}{warning} is produced whenever a \dQuote{generalized
vector} (atomic or \code{\LinkA{list}{list}}) is extended, by something
like \code{x <- 1:3; x[5] <- 6}.

\item[\code{continue}:] a non-empty string setting the prompt used
for lines which continue over one line.

\item[\code{defaultPackages}:] the packages that are attached by
default when \R{} starts up.  Initially set from value of the
environment variable \env{R\_DEFAULT\_PACKAGES}, or if that is unset
to \code{c("datasets", "utils", "grDevices", "graphics", "stats",
        "methods")}.  (Set \env{R\_DEFAULT\_PACKAGES} to \code{NULL} or
a comma-separated list of package names.)   A call to
\code{options} should be in your \file{.Rprofile} file to ensure
that the change takes effect before the base package is
initialized (see \code{\LinkA{Startup}{Startup}}).

\item[\code{deparse.max.lines}:] controls the number of lines used
when deparsing in \code{\LinkA{traceback}{traceback}} and
\code{\LinkA{browser}{browser}}.  Initially unset, and only used if set to
a positive integer.

\item[\code{digits}:] controls the number of digits to print when
printing numeric values.  It is a suggestion only.  Valid values
are 1\dots22 with default 7.  See the warning in
\code{\LinkA{print.default}{print.default}} about values greater than 15.

\item[\code{digits.secs}:] controls the maximum number of digits to
print when formatting time values in seconds.  Valid values
are 0\dots6 with default 0.  See \code{\LinkA{strftime}{strftime}}.

\item[\code{download.file.method}:] Method to be used for
\code{download.file}.  Currently download methods
\code{"internal"}, \code{"wget"} and \code{"lynx"} are available.
There is no default for this option, when \code{method = "auto"}
is chosen: see \code{\LinkA{download.file}{download.file}}.

\item[\code{echo}:] logical.  Only used in non-interactive mode,
when it controls whether input is echoed.  Command-line option
\code{--slave} sets this to \code{FALSE}, but otherwise
it starts the session as \code{TRUE}.

\item[\code{encoding}:] The name of an encoding, default
\code{"native.enc"}).  See \code{\LinkA{connections}{connections}}.

\item[\code{error}:] either a function or an expression governing
the handling of non-catastrophic errors such as those generated by
\code{\LinkA{stop}{stop}} as well as by signals and internally detected
errors.  If the option is a function, a call to that function,
with no arguments, is generated as the expression.  The default
value is \code{NULL}: see \code{\LinkA{stop}{stop}} for the behaviour in
that case.  The functions \code{\LinkA{dump.frames}{dump.frames}} and
\code{\LinkA{recover}{recover}} provide alternatives that allow post-mortem
debugging.

\item[\code{expressions}:] sets a limit on the number of nested
expressions that will be evaluated.  Valid values are
25\dots500000 with default 5000.  If you increase it, you may
also want to start \R{} with a larger protection stack;
see \code{--max-ppsize} in \code{\LinkA{Memory}{Memory}}.  Note too that
you may cause a segfault from overflow of the C stack, and on OSes
where it is possible you may want to increase that.

\item[\code{keep.source}:] When \code{TRUE}, the source code for
functions (newly defined or loaded) is stored in their
\code{"source"} attribute (see \code{\LinkA{attr}{attr}}) allowing
comments to be kept in the right places.

The default is \code{\LinkA{interactive}{interactive}()}, i.e., \code{TRUE} for
interactive use.

\item[\code{keep.source.pkgs}:] As for \code{keep.source}, for
functions in packages loaded by \code{\LinkA{library}{library}} or
\code{\LinkA{require}{require}}.  Defaults to \code{FALSE} unless the
environment variable \env{R\_KEEP\_PKG\_SOURCE} is set to
\code{yes}.

Note this does not apply to packages using lazy-loading or saved
images.  Whether they have kept source is determined when they are
installed (and is almost certainly false).

\item[\code{mailer}:] default mailer used by
\code{\LinkA{bug.report}{bug.report}()}.  Can be \code{"none"}.

\item[\code{max.contour.segments}:] positive integer, defaulting to
\code{250000} and usually not set.  A limit on the number of
segments in a single contour line in \code{\LinkA{contour}{contour}} or
\code{\LinkA{contourLines}{contourLines}}.

\item[\code{max.print}:] integer, defaulting to \code{99999}.
\code{\LinkA{print}{print}} or \code{\LinkA{show}{show}} methods can make use of
this option, to limit the amount of information that is printed,
to something in the order of (and typically slightly less than)
\code{max.print} \emph{entries}.

\item[\code{OutDec}:] one-character string.  The character to be
used as the decimal point in output conversions, that is in
printing, plotting and \code{as.character} but not deparsing.

\item[\code{pager}:] the command used for displaying text files by
\code{\LinkA{file.show}{file.show}}.
Defaults to \file{\$R\_HOME/bin/pager}, which selects a pager via
the \env{PAGER} environment variable (and that usually defaults to
\code{less}).
Can be a character string or an \R{} function, in which case it
needs to accept the same first four arguments as
\code{\LinkA{file.show}{file.show}}.


\item[\code{papersize}:] the default paper format used by
\code{\LinkA{postscript}{postscript}};  set by environment variable
\env{R\_PAPERSIZE} when \R{} is started: if that is unset or invalid
it defaults to
a value derived from the locale category \code{LC\_PAPER}, or
if that is unavailable to a default set when \R{} was built.

\item[\code{printcmd}:] the command used by \code{\LinkA{postscript}{postscript}}
for printing; set by environment variable \env{R\_PRINTCMD} when
\R{} is started.  This should be a command that expects either input
to be piped to \file{stdin} or to be given a single filename
argument.

\item[\code{prompt}:] a non-empty string to be used for \R's prompt;
should usually end in a blank (\code{" "}).

\item[\code{save.defaults}, \code{save.image.defaults}:] see \code{\LinkA{save}{save}}.

\item[\code{scipen}:] integer.  A penalty to be applied
when deciding to print numeric values in fixed or exponential
notation.  Positive values bias towards fixed and negative towards
scientific notation: fixed notation will be preferred unless it is
more than \code{scipen} digits wider.

\item[\code{show.error.messages}:] a logical.  Should error messages
be printed?  Intended for use with \code{\LinkA{try}{try}} or a
user-installed error handler.

\item[\code{stringsAsFactors}:] The default setting for arguments of
\code{\LinkA{data.frame}{data.frame}} and \code{\LinkA{read.table}{read.table}}.

\item[\code{texi2dvi}:] used by the unexported function
\code{texi2dvi} in name space \pkg{tools}.

\item[\code{timeout}:] integer.  The timeout for some Internet
operations, in seconds.  Default 60 seconds.  See
\code{\LinkA{download.file}{download.file}} and \code{\LinkA{connections}{connections}}.

\item[\code{topLevelEnvironment}:] see \code{\LinkA{topenv}{topenv}} and
\code{\LinkA{sys.source}{sys.source}}.

\item[\code{verbose}:] logical.  Should \R{} report extra information
on progress?  Set to \code{TRUE} by the command-line option
\option{--verbose}.

\item[\code{warn}:] sets the handling of warning messages.  If
\code{warn} is negative all warnings are ignored.  If \code{warn}
is zero (the default) warnings are stored until the top--level
function returns.  If fewer than 10 warnings were signalled they
will be printed otherwise a message saying how many (max 50) were
signalled.  An object called \code{last.warning} is
created and can be printed through the function
\code{\LinkA{warnings}{warnings}}.  If \code{warn} is one, warnings are
printed as they occur.  If \code{warn} is two or larger all
warnings are turned into errors.

\item[\code{warning.expression}:] an \R{} code expression to be called
if a warning is generated, replacing the standard message.  If
non-null it is called irrespective of the value of option
\code{warn}.

\item[\code{warnings.length}:] sets the truncation limit for error
and warning messages.  A non-negative integer, with allowed values
100\dots8170, default 1000.

\item[\code{width}:] controls the maximum number of columns on a
line used in printing vectors, matrices and arrays, and when
filling by \code{\LinkA{cat}{cat}}.

Columns are normally the same as characters except in CJK languages.

You may want to change this if you re-size the window that \R{} is
running in.  Valid values are 10\dots10000 with default normally
80.  (The limits on valid values are in file \file{Print.h} and can be
changed by re-compiling \R.)  Some \R{} consoles automatically change
the value when they are resized.

}

The \sQuote{factory-fresh} default settings of some of these options are
\Tabular{ll}{
\code{add.smooth} & \code{TRUE}\\
\code{check.bounds} & \code{FALSE}\\
\code{continue} & \code{"+ "}\\
\code{digits} & \code{7}\\
\code{echo} & \code{TRUE}\\
\code{encoding} & \code{"native.enc"}\\
\code{error} & \code{NULL}\\
\code{expressions} & \code{5000}\\
\code{keep.source} & \code{interactive()}\\
\code{keep.source.pkgs} & \code{FALSE}\\
\code{max.print} & \code{99999}\\
\code{OutDec} & \code{"."}\\
\code{prompt} & \code{"> "}\\
\code{scipen} & \code{0} \\
\code{show.error.messages} & \code{TRUE}\\
\code{timeout} & \code{60}\\
\code{verbose} & \code{FALSE}\\
\code{warn} & \code{0}\\
\code{warnings.length} & \code{1000}\\
\code{width}  & \code{80}\\
}
Others are set from environment variables or are platform-dependent.
\end{Section}
\begin{Section}{Options set in package grDevices}
These will be set when package \pkg{grDevices} (or its name space)
is loaded if not already set.
\describe{
\item[\code{device}:] a character string giving
the name of a function, or the function object itself,
which when called creates a new graphics device of the default
type for that session.  The value of this option defaults to the
normal screen device (e.g., \code{x11}, \code{windows} or
\code{quartz}) for an interactive session, and \code{postscript}
in batch use or if a screen is not available.

\item[\code{locatorBell}:] logical.  Should selection in \code{locator}
and \code{identify} be confirmed by a bell?  Default \code{TRUE}.
Honoured at least on \code{X11} and \code{windows} devices.

\item[\code{par.ask.default}:] logical.  The default for
\code{\LinkA{par}{par}("ask")} when a device is opened.

\item[\code{X11colortype}:] The default colour type for
\code{\LinkA{X11}{X11}} devices.  Default \code{"true"}.

\item[\code{X11fonts}:] character vector of length 2.
See \code{\LinkA{X11}{X11}}.

\item[\code{gamma}:] double.  The default value of
\code{gamma} for \code{\LinkA{X11}{X11}} devices, defaulting to 1
if unset (the default).
}
\end{Section}
\begin{Section}{Options set in package stats}
These will be set when package \pkg{stats} (or its name space)
is loaded if not already set.
\describe{
\item[\code{contrasts}:] the default \code{\LinkA{contrasts}{contrasts}} used in
model fitting such as with \code{\LinkA{aov}{aov}} or \code{\LinkA{lm}{lm}}.
A character vector of length two, the first giving the function to
be used with unordered factors and the second the function to be
used with ordered factors.  By default the elements are named
\code{c("unordered", "ordered")}, but the names are unused.

\item[\code{na.action}:] the name of a function for treating missing
values (\code{\LinkA{NA}{NA}}'s) for certain situations.

\item[\code{show.coef.Pvalues}:] logical, affecting whether P
values are printed in summary tables of coefficients.  See
\code{\LinkA{printCoefmat}{printCoefmat}}.

\item[\code{show.signif.stars}:] logical, should stars be printed on
summary tables of coefficients?  See \code{\LinkA{printCoefmat}{printCoefmat}}.

\item[\code{ts.eps}:] the relative tolerance for certain time series
(\code{\LinkA{ts}{ts}}) computations.  Default \code{1e-05}.

\item[\code{ts.S.compat}:] logical.  Used to select S compatibility
for plotting time-series spectra.  See the description of argument
\code{log} in \code{\LinkA{plot.spec}{plot.spec}}.
}
\end{Section}
\begin{Section}{Options set in package utils}
These will be set when package \pkg{utils} (or its name space)
is loaded if not already set.
\describe{
\item[\code{browser}:] default HTML browser used by
\code{\LinkA{help.start}{help.start}()} on UNIX, or a non-default browser on
Windows.

\item[\code{de.cellwidth}:] integer: the cell widths (number of
characters) to be used in the data editor \code{\LinkA{dataentry}{dataentry}}.
If this is unset (the default), 0, negative or \code{NA}, variable
cell widths are used.

\item[\code{editor}:] a non-empty string.
Sets the default text editor, e.g., for
\code{\LinkA{edit}{edit}}.  Set from the environment variable
\code{VISUAL} on UNIX.

\item[\code{example.ask}:] default for the \code{ask} argument of
\code{\LinkA{example}{example}}.

\item[\code{help.try.all.packages}:] default for an argument of
\code{\LinkA{help}{help}}.

\item[\code{HTTPUserAgent}:] string used as the user agent in HTTP
requests.  If \code{NULL}, HTTP requests will be made without a
user agent header.  The default is \code{R (<version> <platform>
      <arch> <os>)}

\item[\code{internet.info}:] The minimum level of information to be
printed on URL downloads etc.  Default is 2, for failure causes.
Set to 1 or 0 to get more information.

\item[\code{menu.graphics}:] Logical: should graphical menus be
used if available?.  Defaults to \code{TRUE}.  Currently applies
to \code{\LinkA{chooseCRANmirror}{chooseCRANmirror}}, \code{\LinkA{setRepositories}{setRepositories}}
and to select from multiple help files in \code{\LinkA{help}{help}}.

\item[\code{pkgType}:] The default type of packages to be downloaded
and installed -- see \code{\LinkA{install.packages}{install.packages}}.
Possible values are \code{"source"} (the default except under the
CRAN Mac OS X build) and \code{"mac.binary"}.

\item[\code{repos}:] URLs of the repositories for use by
\code{\LinkA{update.packages}{update.packages}}.  Defaults to
\code{c(CRAN="@CRAN@")}, a value that causes some utilities to
prompt for a CRAN mirror.  To avoid this do set the CRAN mirror,
by something like
\code{local(\{r <- getOption("repos"); r["CRAN"] <- "http://my.local.cran";
                   options(repos=r)\})}.

Note that you can add more repositories (Bioconductor and
Omegahat, notably) using \code{\LinkA{setRepositories}{setRepositories}()}.

\item[\code{SweaveHooks}, \code{SweaveSyntax}:] see \code{\LinkA{Sweave}{Sweave}}.

\item[\code{unzip}:] a character string, the path of the command
used for unzipping help files, or \code{"internal"}.
Defaults to the value of \env{R\_UNZIPCMD}, which is set in
\file{etc/Renviron} if an \code{unzip} command was found during
configuration.
}
\end{Section}
\begin{Section}{Options used on Unix only}
\describe{
\item[\code{latexcmd, dvipscmd}:] character strings giving commands
to be used in off-line printing of help pages.

\item[\code{pdfviewer}:] default PDF viewer.  Set from the
environment variable \env{R\_PDFVIEWER}.
}
\end{Section}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{Examples}
\begin{ExampleCode}
options() # printing all current options
op <- options(); str(op) # nicer printing

getOption("width") == options()$width # the latter needs more memory
options(digits = 15)
pi

# set the editor, and save previous value
old.o <- options(editor = "nedit")
old.o

options(check.bounds = TRUE, warn = 1)
x <- NULL; x[4] <- "yes" # gives a warning

options(digits=5)
print(1e5)
options(scipen=3); print(1e5)

options(op)     # reset (all) initial options
options("digits")

## Not run: 
## set contrast handling to be like S
options(contrasts = c("contr.helmert", "contr.poly"))
## End(Not run)

## Not run: 
## on error, terminate the R session with error status 66
options(error = quote(q("no", status=66, runLast=FALSE)))
stop("test it")
## End(Not run)

## Not run: 
## Set error actions for debugging:
## enter browser on error, see ?recover:
options(error = recover)
## allows to call debugger() afterwards, see ?debugger:
options(error = dump.frames)
## A possible setting for non-interactive sessions
options(error = quote({dump.frames(to.file=TRUE); q()}))
## End(Not run)\end{ExampleCode}
\end{Examples}

