encodeString              package:base              R Documentation

_E_n_c_o_d_e _C_h_a_r_a_c_t_e_r _V_e_c_t_o_r _a_s _f_o_r _P_r_i_n_t_i_n_g

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

     'encodeString' escapes the strings in a character vector in the
     same way 'print.default' does, and optionally fits the encoded
     strings within a field width.

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

     encodeString(x, width = 0, quote = "", na.encode = TRUE,
                  justify = c("left", "right", "centre", "none"))

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

       x: A character vector, or an object that can be coerced to one
          by 'as.character'.

   width: integer: the minimum field width.  If 'NULL' or 'NA', this is
          taken to be the largest field width needed for any element of
          'x'.

   quote: character: quoting character, if any.

na.encode: logical: should 'NA' strings be encoded?

 justify: character: partial matches are allowed.  If padding to the
          minimum field width is needed, how should spaces be inserted?
          'justify == "none"' is equivalent to 'width = 0', for
          consistency with 'format.default'.

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

     This escapes backslash and the control characters '\a' (bell),
     '\b' (backspace), '\f' (formfeed), '\n' (line feed), '\r'
     (carriage return), '\t' (tab) and '\v' (vertical tab) as well as
     any non-printable characters in a single-byte locale, which are
     printed in octal notation ('\xyz' with leading zeroes). (Which
     characters are non-printable depends on the current locale.) See
     'print.default' for how non-printable characters are handled in
     multi-byte locales.

     If 'quote' is a single or double quote any embedded quote of the
     same type is escaped.  Note that justification is of the quoted
     string, hence spaces are added outside the quotes.

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

     A character vector of the same length as 'x', with the same
     attributes (including names and dimensions) but with no class set.

_N_o_t_e:

     The default for 'width' is different from 'format.default', which
     does similar things for character vectors but without encoding
     using escapes.

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

     'print.default'

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

     x <- "ab\bc\ndef"
     print(x)
     cat(x) # interprets escapes
     cat(encodeString(x), "\n", sep="") # similar to print()

     factor(x) # makes use of this to print the levels

     x <- c("a", "ab", "abcde")
     encodeString(x, width = NA) # left justification
     encodeString(x, width = NA, justify = "c")
     encodeString(x, width = NA, justify = "r")
     encodeString(x, width = NA, quote = "'", justify = "r")

