tabs_as_spaces | R Documentation |
Finds horizontal tab characters (0x09) in a string and replaces them with the spaces that produce the same horizontal offset.
tabs_as_spaces(
x,
tab.stops = getOption("fansi.tab.stops", 8L),
warn = getOption("fansi.warn", TRUE),
ctl = "all"
)
x |
character vector or object coercible to character; any tabs therein will be replaced. |
tab.stops |
integer(1:n) indicating position of tab stops to use when converting tabs to spaces. If there are more tabs in a line than defined tab stops the last tab stop is re-used. For the purposes of applying tab stops, each input line is considered a line and the character count begins from the beginning of the input line. |
warn |
TRUE (default) or FALSE, whether to warn when potentially
problematic Control Sequences are encountered. These could cause the
assumptions |
ctl |
character, which Control Sequences should be treated
specially. Special treatment is context dependent, and may include
detecting them and/or computing their display/character width as zero. For
the SGR subset of the ANSI CSI sequences, and OSC hyperlinks,
|
Since we do not know of a reliable cross platform means of detecting tab stops you will need to provide them yourself if you are using anything outside of the standard tab stop every 8 characters that is the default.
character, x
with tabs replaced by spaces, with elements
possibly converted to UTF-8.
Non-ASCII strings are converted to and returned in UTF-8 encoding. The
ctl
parameter only affects which Control Sequences are considered zero
width. Tabs will always be converted to spaces, irrespective of the ctl
setting.
?fansi
for details on how Control Sequences are
interpreted, particularly if you are getting unexpected results,
unhandled_ctl
for detecting bad control sequences.
string <- '1\t12\t123\t1234\t12345678'
tabs_as_spaces(string)
writeLines(
c(
'-------|-------|-------|-------|-------|',
tabs_as_spaces(string)
) )
writeLines(
c(
'-|--|--|--|--|--|--|--|--|--|--|',
tabs_as_spaces(string, tab.stops=c(2, 3))
) )
writeLines(
c(
'-|--|-------|-------|-------|',
tabs_as_spaces(string, tab.stops=c(2, 3, 8))
) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.