character                package:base                R Documentation

_C_h_a_r_a_c_t_e_r _V_e_c_t_o_r_s

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

  length: desired length.

       x: object to be coerced or tested.

     ...: further arguments passed to or from other methods.

_D_e_t_a_i_l_s:

     'as.character' and 'is.character' are generic: you can write
     methods to handle specific classes of objects, see
     InternalMethods.  Further, for 'as.character' the default method
     calls 'as.vector', 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 decimal
     places (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 coversion 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'.

_V_a_l_u_e:

     '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' it strips attributes including names. For lists
     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.  (Methods should always
     return 'FALSE' for classes which are not based on a character
     vector, but can return 'FALSE' even for those which are.)

_N_o_t_e:

     'as.character' truncates components of language objects to 500
     characters (was about 70 before 1.3.1).

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     'paste', 'substr' and 'strsplit' for character concatenation and
     splitting, 'chartr' for character translation and casefolding
     (e.g., upper to lower case) and 'sub', 'grep' etc for string
     matching and substitutions.  Note that 'help.search(keyword =
     "character")' gives even more links. 'deparse', which is normally
     preferable to 'as.character' for language objects.

_E_x_a_m_p_l_e_s:

     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)

