ansi_collapse | R Documentation |
Features:
custom separator (sep
),
custom separator for length-two input (sep2
),
custom last separator (last
),
adds ellipsis to truncated strings,
uses Unicode ellipsis character on UTF-8 console,
can collapse "from both ends", with style = "both-ends"
,
can consider a limit for the display width of the result, in characters,
handles ANSI control sequences correctly when measuring display width.
ansi_collapse(
x,
sep = ", ",
sep2 = " and ",
last = ", and ",
trunc = Inf,
width = Inf,
ellipsis = symbol$ellipsis,
style = c("both-ends", "head")
)
x |
Character vector, or an object with an |
sep |
Separator. A character string. |
sep2 |
Separator for the special case that |
last |
Last separator, if there is no truncation. E.g. use
|
trunc |
Maximum number of elements to show. For |
width |
Limit for the display width of the result, in characters.
This is a hard limit, and the output will never exceed it.
This argument is not implemented for the |
ellipsis |
Character string to use at the place of the truncation. By default, the Unicode ellipsis character is used if the console is UTF-8, and three dots otherwise. |
style |
Truncation style:
|
Character scalar. It is NA_character_
if any elements in x
are NA
.
glue_collapse
in the glue package inspired this function.
ansi_collapse(letters)
# truncate
ansi_collapse(letters, trunc = 5)
# head style
ansi_collapse(letters, trunc = 5, style = "head")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.