utf8_format {utf8} | R Documentation |
UTF-8 Text Formatting
Description
Format a character object for UTF-8 printing.
Usage
utf8_format(x, trim = FALSE, chars = NULL, justify = "left",
width = NULL, na.encode = TRUE, quote = FALSE,
na.print = NULL, print.gap = NULL, utf8 = NULL, ...)
Arguments
x |
character object. |
trim |
logical scalar indicating whether to suppress padding spaces around elements. |
chars |
integer scalar indicating the maximum number of
character units to display. Wide characters like emoji take
two character units; combining marks and default ignorables
take none. Longer strings get truncated and suffixed or prefixed
with an ellipsis ( |
justify |
justification; one of |
width |
the minimum field width; set to |
na.encode |
logical scalar indicating whether to encode
|
quote |
logical scalar indicating whether to format for a context
with surrounding double-quotes ( |
na.print |
character string (or |
print.gap |
non-negative integer (or |
utf8 |
logical scalar indicating whether to format for a UTF-8
capable display (ASCII-only otherwise), or |
... |
further arguments passed from other methods. Ignored. |
Details
utf8_format
formats a character object for printing, optionally
truncating long character strings.
Value
A character object with the same attributes as x
but with
Encoding
set to "UTF-8"
for elements that can be
converted to valid UTF-8 and "bytes"
for others.
See Also
Examples
# the second element is encoded in latin-1, but declared as UTF-8
x <- c("fa\u00E7ile", "fa\xE7ile", "fa\xC3\xA7ile")
Encoding(x) <- c("UTF-8", "UTF-8", "bytes")
# formatting
utf8_format(x, chars = 3)
utf8_format(x, chars = 3, justify = "centre", width = 10)
utf8_format(x, chars = 3, justify = "right")