| 1 |
\name{applyTemplate} |
| 2 |
\alias{applyTemplate} |
| 3 |
\alias{template} |
| 4 |
\title{Apply a Formatting Template to a Numeric or Character Vector} |
| 5 |
\description{ |
| 6 |
\code{applyTemplate} is called internally by \code{\link{mtable}} |
| 7 |
to format coefficients and summary statistics. |
| 8 |
} |
| 9 |
\usage{ |
| 10 |
applyTemplate(x,template,float.style=getOption("float.style"), |
| 11 |
digits=min(3,getOption("digits")), |
| 12 |
signif.symbols=getOption("signif.symbols")) |
| 13 |
} |
| 14 |
\arguments{ |
| 15 |
\item{x}{a numeric or character vector to be formatted, or a list of such vectors.} |
| 16 |
\item{template}{a character vector that defines the template, see details.} |
| 17 |
\item{float.style}{A character string that is passed to \code{\link{formatC}} |
| 18 |
by \code{applyTemplate}; valid values |
| 19 |
are \code{"e"}, \code{"f"}, \code{"g"}, \code{"fg"}, |
| 20 |
\code{"E"}, and \code{"G"}. By default, the \code{float.style} |
| 21 |
setting of \code{\link{options}} is used. The `factory fresh' setting is |
| 22 |
\code{options(float.style="f")} |
| 23 |
} |
| 24 |
\item{digits}{number of significant digits to use if not specified in |
| 25 |
the template.} |
| 26 |
\item{signif.symbols}{a named vector that specifies how significance levels |
| 27 |
are symbolically indicated, values of the vector specify |
| 28 |
significance levels and names specify the symbols. By default, the |
| 29 |
\code{signif.symbols} setting of \code{\link{options}} is used. The "factory-fresh" setting is |
| 30 |
\code{options(signif.symbols=c("***"=.001,"**"=.01,"*"=.05))}. |
| 31 |
} |
| 32 |
} |
| 33 |
\details{ |
| 34 |
Character vectors that are used as templates may be arbitrary. However, |
| 35 |
certain character sequences may form \emph{template expressions}. |
| 36 |
A template expression is of the form \code{($<POS>:<Format spec>)}, |
| 37 |
where "\code{($}" indicates the start of a template expression, |
| 38 |
"\code{<POS>}" stands for either an index or name that selects an |
| 39 |
element from \code{x} and "\code{<Format spec>}" stands for a |
| 40 |
\emph{format specifier}. It may contain an letter indicating the |
| 41 |
style in which the vector element selected by \code{<POS>} |
| 42 |
will be formatted by \code{\link{formatC}}, it may contain |
| 43 |
a number as the number of significant digits, a "\code{#}" |
| 44 |
indicating that the number of signifcant digits will be at most that given |
| 45 |
by \code{getOption("digits")}, or \code{*} that means that |
| 46 |
the value will be formatted as a significance symbol. |
| 47 |
} |
| 48 |
\value{ |
| 49 |
\code{applyTemplate} returns a character vector in which template |
| 50 |
expressions in \code{template} are substituted by formatted values from \code{x}. |
| 51 |
If \code{template} is an array then the return value is also an array of |
| 52 |
the same shape. |
| 53 |
} |
| 54 |
\examples{ |
| 55 |
applyTemplate(c(a=.0000000000000304,b=3),template=c("($1:g7#)($a:*)"," (($1:f2)) ")) |
| 56 |
applyTemplate(c(a=.0000000000000304,b=3),template=c("($a:g7#)($a:*)"," (($b:f2)) ")) |
| 57 |
} |
| 58 |
\keyword{misc} |
| 59 |
\keyword{utilities} |