[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  character: Character Vectors

##  Description

Create or test for objects of type ` "character" ` .

##  Usage

    
    
    character(length = 0)
    as.character(x, …)
    is.character(x)

##  Arguments

length

A non-negative integer specifying the desired length. Double values will be
coerced to integer: supplying an argument of length other than one is an
error.

x

object to be coerced or tested.

…

further arguments passed to or from other methods.

##  Value

` character ` creates a character vector of the specified length. The elements
of the vector are all equal to ` "" ` .

` as.character ` attempts to coerce its argument to character type; like ` [
as.vector ](/link/as.vector?package=base&version=3.6.2) ` it strips attributes
including names. For lists and pairlists (including [ language objects
](/link/language%20objects?package=base&version=3.6.2) such as calls) it
deparses the elements individually, except that it extracts the first element
of length-one character vectors.

` is.character ` returns ` TRUE ` or ` FALSE ` depending on whether its
argument is of character type or not.

##  Details

` as.character ` and ` is.character ` are generic: you can write methods to
handle specific classes of objects, see [ InternalMethods
](/link/InternalMethods?package=base&version=3.6.2) . Further, for `
as.character ` the default method calls ` [ as.vector
](/link/as.vector?package=base&version=3.6.2) ` , so dispatch is first on
methods for ` as.character ` and then for methods for ` as.vector ` .

` as.character ` represents real and complex numbers to 15 significant digits
(technically the compiler's setting of the ISO C constant ` 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 ` [ format
](/link/format?package=base&version=3.6.2) ` .

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ options ](/link/options?package=base&version=3.6.2) ` : option ` scipen `
affects the conversion of numbers.

` [ paste ](/link/paste?package=base&version=3.6.2) ` , ` [ substr
](/link/substr?package=base&version=3.6.2) ` and ` [ strsplit
](/link/strsplit?package=base&version=3.6.2) ` for character concatenation and
splitting, ` [ chartr ](/link/chartr?package=base&version=3.6.2) ` for
character translation and casefolding (e.g., upper to lower case) and ` [ sub
](/link/sub?package=base&version=3.6.2) ` , ` [ grep
](/link/grep?package=base&version=3.6.2) ` etc for string matching and
substitutions. Note that ` help.search(keyword = "character") ` gives even
more links.

` [ deparse ](/link/deparse?package=base&version=3.6.2) ` , which is normally
preferable to ` as.character ` for [ language objects
](/link/language%20objects?package=base&version=3.6.2) .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fcharacter&utm_source=r-docs&utm_medium=docs&utm_term=character&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    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 fro