strip_ctl {fansi} | R Documentation |
Removes Control Sequences from strings. By default it will
strip all known Control Sequences, including ANSI CSI
sequences, two character sequences starting with ESC, and all C0 control
characters, including newlines. You can fine tune this behavior with the
strip
parameter. strip_sgr
only strips ANSI CSI SGR sequences.
strip_ctl(x, strip = "all", warn = getOption("fansi.warn")) strip_sgr(x, warn = getOption("fansi.warn"))
x |
a character vector or object that can be coerced to character. |
strip |
character, any combination of the following values (see details):
|
warn |
TRUE (default) or FALSE, whether to warn when potentially
problematic Control Sequences are encountered. These could cause the
assumptions |
The strip
value contains the names of non-overlapping subsets of the
known Control Sequences (e.g. "csi" does not contain "sgr", and "c0" does
not contain newlines). The one exception is "all" which means strip every
known sequence. If you combine "all" with any other option then everything
but that option will be stripped.
character vector of same length as x with ANSI escape sequences stripped
Non-ASCII strings are converted to and returned in UTF-8 encoding.
fansi for details on how Control Sequences are interpreted, particularly if you are getting unexpected results.
string <- "hello\033k\033[45p world\n\033[31mgoodbye\a moon" strip_ctl(string) strip_ctl(string, c("nl", "c0", "sgr", "csi", "esc")) # equivalently strip_ctl(string, "sgr") strip_ctl(string, c("c0", "esc")) ## everything but C0 controls, we need to specify "nl" ## in addition to "c0" since "nl" is not part of "c0" ## as far as the `strip` argument is concerned strip_ctl(string, c("all", "nl", "c0")) ## convenience function, same as `strip_ctl(strip='sgr')` strip_sgr(string)