utf8_print: Print UTF-8 Text

Description Usage Arguments Details Value See Also Examples

View source: R/utf8_print.R

Description

Print a UTF-8 character object.

Usage

1
2
3
4
utf8_print(x, chars = NULL, quote = TRUE, na.print = NULL,
           print.gap = NULL, right = FALSE, max = NULL,
           names = NULL, rownames = NULL, escapes = NULL,
           display = TRUE, style = TRUE, utf8 = NULL, ...)

Arguments

x

character object.

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 ("..." in C locale, "\u2026" in others). Set to NULL to limit output to the line width as determined by getOption("width").

quote

logical scalar indicating whether to put surrounding double-quotes ('"') around character strings and escape internal double-quotes.

na.print

character string (or NULL) indicating the encoding for NA values. Ignored when na.encode is FALSE.

print.gap

non-negative integer (or NULL) giving the number of spaces in gaps between columns; set to NULL or 1 for a single space.

right

logical scalar indicating whether to right-justify character strings.

max

non-negative integer (or NULL) indicating the maximum number of elements to print; set to getOption("max.print") if argument is NULL.

names

a character string specifying the display style for the (column) names, as an ANSI SGR parameter string.

rownames

a character string specifying the display style for the row names, as an ANSI SGR parameter string.

escapes

a character string specifying the display style for the backslash escapes, as an ANSI SGR parameter string.

display

logical scalar indicating whether to optimize the encoding for display, not byte-for-byte data transmission.

style

logical scalar indicating whether to apply ANSI terminal escape codes to style the output. Ignored when output_ansi() is FALSE.

utf8

logical scalar indicating whether to optimize results for a UTF-8 capable display, or NULL to set as the result of output_utf8(). Ignored when output_utf8() is FALSE.

...

further arguments passed from other methods. Ignored.

Details

utf8_print prints a character object after formatting it with utf8_format.

For ANSI terminal output (when output_ansi() is TRUE), you can style the row and column names with the rownames and names parameters, specifying an ANSI SGR parameter string; see https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters.

Value

The function returns x invisibly.

See Also

utf8_format.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# printing (assumes that output is capable of displaying Unicode 10.0.0)
print(intToUtf8(0x1F600 + 0:79)) # with default R print function
utf8_print(intToUtf8(0x1F600 + 0:79)) # with utf8_print, truncates line
utf8_print(intToUtf8(0x1F600 + 0:79), chars = 1000) # higher character limit

# in C locale, output ASCII (same results on all platforms)
oldlocale <- Sys.getlocale("LC_CTYPE")
invisible(Sys.setlocale("LC_CTYPE", "C")) # switch to C locale
utf8_print(intToUtf8(0x1F600 + 0:79))
invisible(Sys.setlocale("LC_CTYPE", oldlocale)) # switch back to old locale

# Mac and Linux only: style the names
# see https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
utf8_print(matrix(as.character(1:20), 4, 5),
           names = "1;4", rownames = "2;3")

Example output

[1] "<U+0001F600><U+0001F601><U+0001F602><U+0001F603><U+0001F604><U+0001F605><U+0001F606><U+0001F607><U+0001F608><U+0001F609><U+0001F60A><U+0001F60B><U+0001F60C><U+0001F60D><U+0001F60E><U+0001F60F><U+0001F610><U+0001F611><U+0001F612><U+0001F613><U+0001F614><U+0001F615><U+0001F616><U+0001F617><U+0001F618><U+0001F619><U+0001F61A><U+0001F61B><U+0001F61C><U+0001F61D><U+0001F61E><U+0001F61F><U+0001F620><U+0001F621><U+0001F622><U+0001F623><U+0001F624><U+0001F625><U+0001F626><U+0001F627><U+0001F628><U+0001F629><U+0001F62A><U+0001F62B><U+0001F62C><U+0001F62D><U+0001F62E><U+0001F62F><U+0001F630><U+0001F631><U+0001F632><U+0001F633><U+0001F634><U+0001F635><U+0001F636><U+0001F637><U+0001F638><U+0001F639><U+0001F63A><U+0001F63B><U+0001F63C><U+0001F63D><U+0001F63E><U+0001F63F><U+0001F640><U+0001F641><U+0001F642><U+0001F643><U+0001F644><U+0001F645><U+0001F646><U+0001F647><U+0001F648><U+0001F649><U+0001F64A><U+0001F64B><U+0001F64C><U+0001F64D><U+0001F64E><U+0001F64F>"
[1] "\U0001f600\U0001f601\U0001f602\U0001f603\U0001f604\U0001f605\U0001f606..."
[1] "\U0001f600\U0001f601\U0001f602\U0001f603\U0001f604\U0001f605\U0001f606\U0001f607\U0001f608\U0001f609\U0001f60a\U0001f60b\U0001f60c\U0001f60d\U0001f60e\U0001f60f\U0001f610\U0001f611\U0001f612\U0001f613\U0001f614\U0001f615\U0001f616\U0001f617\U0001f618\U0001f619\U0001f61a\U0001f61b\U0001f61c\U0001f61d\U0001f61e\U0001f61f\U0001f620\U0001f621\U0001f622\U0001f623\U0001f624\U0001f625\U0001f626\U0001f627\U0001f628\U0001f629\U0001f62a\U0001f62b\U0001f62c\U0001f62d\U0001f62e\U0001f62f\U0001f630\U0001f631\U0001f632\U0001f633\U0001f634\U0001f635\U0001f636\U0001f637\U0001f638\U0001f639\U0001f63a\U0001f63b\U0001f63c\U0001f63d\U0001f63e\U0001f63f\U0001f640\U0001f641\U0001f642\U0001f643\U0001f644\U0001f645\U0001f646\U0001f647\U0001f648\U0001f649\U0001f64a\U0001f64b\U0001f64c\U0001f64d\U0001f64e\U0001f64f"
[1] "\U0001f600\U0001f601\U0001f602\U0001f603\U0001f604\U0001f605\U0001f606..."
     [,1] [,2] [,3] [,4] [,5]
[1,] "1"  "5"  "9"  "13" "17"
[2,] "2"  "6"  "10" "14" "18"
[3,] "3"  "7"  "11" "15" "19"
[4,] "4"  "8"  "12" "16" "20"

utf8 documentation built on July 24, 2021, 5:07 p.m.