ansi_substring | R Documentation |
This is the color-aware counterpart of base::substring()
.
It works exactly like the original, but keeps the colors in the
substrings. The ANSI escape sequences are ignored when
calculating the positions within the string.
ansi_substring(text, first, last = 1000000L)
text |
Character vector, potentially ANSI styled, or a vector to
coerced to character. It is recycled to the longest of |
first |
Starting index or indices, recycled to match the length
of |
last |
Ending index or indices, recycled to match the length
of |
Character vector of the same length as x
, containing
the requested substrings. ANSI styles are retained.
Other ANSI string operations:
ansi_align()
,
ansi_columns()
,
ansi_nchar()
,
ansi_strsplit()
,
ansi_strtrim()
,
ansi_strwrap()
,
ansi_substr()
,
ansi_toupper()
,
ansi_trimws()
str <- paste(
col_red("red"),
"default",
col_green("green")
)
cat(str, "\n")
cat(ansi_substring(str, 1, 5), "\n")
cat(ansi_substring(str, 1, 15), "\n")
cat(ansi_substring(str, 3, 7), "\n")
substring(ansi_strip(str), 1, 5)
substring(ansi_strip(str), 1, 15)
substring(ansi_strip(str), 3, 7)
str2 <- paste(
"another",
col_red("multi-", style_underline("style")),
"text"
)
cat(str2, "\n")
cat(ansi_substring(str2, c(3,5), c(7, 18)), sep = "\n")
substring(ansi_strip(str2), c(3,5), c(7, 18))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.