Movatterモバイル変換


[0]ホーム

URL:


encodeString {base}R Documentation

Encode Character Vector as for Printing

Description

encodeString escapes the strings in a character vector in thesame wayprint.default does, and optionally fits the encodedstrings within a field width.

Usage

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

Arguments

x

a character vector, or an object that can be coerced to onebyas.character.

width

integer: the minimum field width. IfNULL orNA, this is taken to be the largest field width needed forany element ofx.

quote

character: quoting character, if any.

na.encode

logical: shouldNA strings be encoded?

justify

character: partial matches are allowed. If padding tothe minimum field width is needed, how should spaces be inserted?justify == "none" is equivalent towidth = 0, forconsistency withformat.default.

Details

This escapes backslash and the control characters ‘⁠\a⁠’ (bell),‘⁠\b⁠’ (backspace), ‘⁠\f⁠’ (form feed),‘⁠\n⁠’ (line feed, aka “newline”),‘⁠\r⁠’ (carriage return), ‘⁠\t⁠’ (tab) and ‘⁠\v⁠’(vertical tab) as well as any non-printable characters in asingle-byte locale, which are printed in octal notation (‘⁠\xyz⁠’with leading zeroes).

Which characters are non-printable depends on the current locale.Windows' reporting of printable characters is unreliable, so there allother control characters are regarded as non-printable, and allcharacters with codes 32–255 as printable in a single-byte locale.Seeprint.default for how non-printable characters arehandled in multi-byte locales.

Ifquote is a single or double quote any embedded quote of thesame type is escaped. Note that justification is of the quotedstring, hence spaces are added outside the quotes.

Value

A character vector of the same length asx, with the sameattributes (including names and dimensions) but with no class set.

Marked UTF-8 encodings are preserved.

Note

The default forwidth is different fromformat.default,which does similar things for character vectors but without encodingusing escapes.

See Also

print.default

Examples

x <- "ab\bc\ndef"print(x)cat(x) # interprets escapescat(encodeString(x), "\n", sep = "") # similar to print()factor(x) # makes use of this to print the levelsx <- c("a", "ab", "abcde")encodeString(x) # width = 0: use as little as possibleencodeString(x, 2) # use two or more (left justified)encodeString(x, width = NA) # left justificationencodeString(x, width = NA, justify = "c")encodeString(x, width = NA, justify = "r")encodeString(x, width = NA, quote = "'", justify = "r")

[Packagebase version 4.6.0Index]

[8]ページ先頭

©2009-2025 Movatter.jp