\Header{format}{Encode in a Common Format}
\methalias{format.default}{format}
\methalias{format.pval}{format}
\keyword{character}{format}
\keyword{print}{format}
\begin{Description}\relax
Format an \R{} object for pretty printing: \code{format.pval} is
intended for formatting p-values.\end{Description}
\begin{Usage}
\begin{verbatim}
format(x, ...)
format.default(x, trim = FALSE, digits = getOption("digits"))
format.pval(x, digits = max(1, getOption("digits") - 2),
            eps = .Machine$double.eps)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] any \R{} object (conceptually); typically numeric.
\item[\code{trim}] logical; if \code{TRUE}, leading blanks are trimmed off the
strings.
\item[\code{digits}] how many significant digits are to be used for
\code{\Link{numeric} x}. This is a suggestion: enough decimal
places will be used so that the smallest (in magnitude) number has
this many significant digits.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
These functions convert their first argument to a vector (or array) of
character strings which have a common format (as is done by
\code{\Link{print}}).  The trimming with \code{trim = TRUE} is useful
when the strings are to be used for plot \code{\Link{axis}} annotation.

\code{format.pval} is mainly an auxiliary function for
\code{\Link{print.summary.lm}} etc., does separate formatting for
fixed, floating point and very small values (those \code{< eps}).

The function \code{\Link{formatC}} provides a rather more flexible
formatting facility for numbers, but does \emph{not} provide a common
format for several numbers.\end{Details}
\begin{Note}\relax
Currently \code{format} loses trailing zeroes, so \code{format(6.001,
    digits=2)} gives \code{"6"} and \code{format(c(6.0, 13.1),
    digits=2)} gives \code{c(" 6", "13")}.

Character(s) \code{"} in input strings \code{x} are escaped to \code{\bsl{}"}.\end{Note}
\begin{SeeAlso}\relax
\code{\Link{formatC}}, \code{\Link{paste}}, \code{\Link{as.character}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
format(1:10)

p <- c(47,13,2,.1,.023,.0045, 1e-100)/1000
format.pval(p)
format.pval(p / 0.9)
format.pval(p / 0.9, dig=3)
\end{ExampleCode}
\end{Examples}

