\Header{match.arg}{Argument Verification Using Partial Matching}
\keyword{programming}{match.arg}
\begin{Usage}
\begin{verbatim}
match.arg(arg)
match.arg(arg, choices)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{arg}] a character string
\item[\texttt{choices}] a character vector of candidate values
\end{ldescription}
\end{Arguments}
\begin{Description}
\texttt{match.arg} matches \texttt{arg} against a table of candidate
values as specified by \texttt{choices}.  In the one-argument form
\texttt{match.arg(arg)}, the choices are obtained from a default setting
for the formal argument \texttt{arg} of the function from which
\texttt{match.arg} was called.

Matching is done using \texttt{\Link{pmatch}}, so \texttt{arg} may be
abbreviated.\end{Description}
\begin{Value}
The unabbreviated version of the unique partial match if there is one;
otherwise, an error is signalled.\end{Value}
\begin{SeeAlso}
\texttt{\Link{pmatch}}, \texttt{\Link{match.fun}}, \texttt{\Link{match.call}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Extends the example for `switch'
center <- function(x, type = c("mean", "median", "trimmed")) {
  type <- match.arg(type)
  switch(type,
         mean = mean(x),
         median = median(x),
         trimmed = mean(x, trim = .1))
}
x <- rcauchy(10)
center(x, "t")       # Works
center(x, "med")     # Works
center(x, "m")       # Error

\end{ExampleCode}
\end{Examples}

