
Last chance! 50% off unlimited learning
Sale ends in
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.encodeString(x, width = 0, quote = "", na.encode = TRUE,
justify = c("left", "right", "centre", "none"))
as.character
.NULL
or
NA
, this is taken to be the largest field width needed for
any element of x
.NA
strings be encoded?justify == "none"
is equivalent to width = 0
, for
consistency with format.default
.x
, with the same
attributes (including names and dimensions) but with no class set.As from R3.0.0, marked UTF-8 encodings are preserved.
Which characters are non-printable depends on the current locale.
Windows' reporting of printable characters is unreliable, so there all
other control characters are regarded as non-printable, and all
characters with codes 32--255 as printable in a single-byte 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.
print.default
x <- "abbc
def"
print(x)
cat(x) # interprets escapes
cat(encodeString(x), "", sep = "") # similar to print()
factor(x) # makes use of this to print the levels
x <- c("a", "ab", "abcde")
encodeString(x) # width = 0: use as little as possible
encodeString(x, 2) # use two or more (left justified)
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")
Run the code above in your browser using DataLab