\HeaderA{character}{Character Vectors}{character}
\aliasA{as.character}{character}{as.character}
\methaliasA{as.character.default}{character}{as.character.default}
\methaliasA{as.character.factor}{character}{as.character.factor}
\aliasA{is.character}{character}{is.character}
\keyword{character}{character}
\keyword{classes}{character}
\begin{Description}\relax
Create or test for objects of type \code{"character"}.
\end{Description}
\begin{Usage}
\begin{verbatim}
character(length = 0)
as.character(x, ...)
is.character(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{length}] desired length.
\item[\code{x}] object to be coerced or tested.
\item[\code{...}] further arguments passed to or from other methods.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{as.character} and \code{is.character} are generic: you can
write methods to handle specific classes of objects,
see \LinkA{InternalMethods}{InternalMethods}.  Further, for \code{as.character} the
default method calls \code{\LinkA{as.vector}{as.vector}}, so dispatch is first on
methods for \code{as.character} and then for methods for \code{as.vector}.

\code{as.character} represents real and complex numbers to 15 significant
digits (technically the compiler's setting of the ISO C constant
\code{DBL\_DIG}, which will be 15 on machines supporting IEC60559
arithmetic according to the C99 standard).  This ensures that all the
digits in the result will be reliable (and not the result of
representation error), but does mean that conversion to character and
back to numeric may change the number.  If you want to convert numbers
to character with the maximum possible precision, use
\code{\LinkA{format}{format}}.
\end{Details}
\begin{Value}
\code{character} creates a character vector of the specified length.
The elements of the vector are all equal to \code{""}.

\code{as.character} attempts to coerce its argument to character type;
like \code{\LinkA{as.vector}{as.vector}} it strips attributes including names.
For lists it deparses the elements individually, except that it
extracts the first element of length-one character vectors.

\code{is.character} returns \code{TRUE} or \code{FALSE} depending on
whether its argument is of character type or not.
\end{Value}
\begin{Note}\relax
\code{as.character} truncates components of language objects to 500
characters (was about 70 before 1.3.1).
\end{Note}
\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{SeeAlso}\relax
\code{\LinkA{paste}{paste}}, \code{\LinkA{substr}{substr}} and \code{\LinkA{strsplit}{strsplit}}
for character concatenation and splitting,
\code{\LinkA{chartr}{chartr}} for character translation and casefolding (e.g.,
upper to lower case) and \code{\LinkA{sub}{sub}}, \code{\LinkA{grep}{grep}} etc for
string matching and substitutions.  Note that
\code{help.search(keyword = "character")} gives even more links.
\code{\LinkA{deparse}{deparse}}, which is normally preferable to
\code{as.character} for language objects.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
form <- y ~ a + b + c
as.character(form)  ## length 3
deparse(form)       ## like the input

a0 <- 11/999          # has a repeating decimal representation
(a1 <- as.character(a0))
format(a0, digits=16) # shows one more digit
a2 <- as.numeric(a1)
a2 - a0               # normally around -1e-17
as.character(a2)      # normally different from a1
print(c(a0, a2), digits = 16)
\end{ExampleCode}
\end{Examples}

