| ansi_strsplit | R Documentation |
This is the color-aware counterpart of base::strsplit().
It works almost exactly like the original, but keeps the colors in the
substrings.
ansi_strsplit(x, split, ...)
x |
Character vector, potentially ANSI styled, or a vector to coerced to character. |
split |
Character vector of length 1 (or object which can be coerced to
such) containing regular expression(s) (unless |
... |
Extra arguments are passed to |
A list of the same length as x, the i-th element of
which contains the vector of splits of x[i]. ANSI styles are
retained.
Other ANSI string operations:
ansi_align(),
ansi_columns(),
ansi_nchar(),
ansi_strtrim(),
ansi_strwrap(),
ansi_substr(),
ansi_substring(),
ansi_toupper(),
ansi_trimws()
str <- paste0(
col_red("I am red---"),
col_green("and I am green-"),
style_underline("I underlined")
)
cat(str, "\n")
# split at dashes, keep color
cat(ansi_strsplit(str, "[-]+")[[1]], sep = "\n")
strsplit(ansi_strip(str), "[-]+")
# split to characters, keep color
cat(ansi_strsplit(str, "")[[1]], "\n", sep = " ")
strsplit(ansi_strip(str), "")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.