tabs_as_spaces {fansi} | 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"), warn = getOption("fansi.warn"))
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 |
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.
fansi for details on how Control Sequences are interpreted, particularly if you are getting unexpected results.
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)) ) )