encodeString {base}R Documentation

Encode Character Vector as for Printing

Description

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.

Usage

encodeString(x, w = 0, quote = "", na = TRUE,
             justify = c("left", "right", "centre"))

Arguments

x A character vector, or an object that can be coerced to one by as.character.
w integer: the minimum field width. If NA, this is taken to be the largest field width needed for any element of x.
quote character: quoting character, if any.
na 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?

Details

This escapes backslash and the control characters \a (bell), \b (backspace), \f (formfeed), \n (line feed), \r (carriage return), \t (tab), \v (vertical tab) and \0 (nul) as well as any non-printable characters, which are printed in octal notation (\xyz with leading zeroes). (Windows' reporting of printable characters is unreliable, so all other control characters are regarded as non-printable, and all characters with codes 32–255 as printable.)

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.

Value

A character vector of the same length as x, with the same attributes (including names and dimensions).

See Also

print.default

Examples

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, w = NA) # left justification
encodeString(x, w = NA, justify = "c")
encodeString(x, w = NA, justify = "r")
encodeString(x, w = NA, quote = "'", justify = "r")

[Package base version 2.1.0 Index]