Last active
May 20, 2016 05:48
-
-
Save artemklevtsov/da32e34c3d98666a762a to your computer and use it in GitHub Desktop.
Based on the stringi::stri_pad and tools::showNonASCII
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str_pad <- function(str, width = floor(0.9 * getOption("width")), side = c("left", "both", "right")) { | |
side <- match.arg(side) | |
asc <- iconv(str, "latin1", "ASCII") | |
if (any(is.na(asc) | asc != str)) | |
width <- width + nchar(str, "bytes") - nchar(str, "width") | |
switch(side, | |
left = sprintf("%*s", width, str), | |
right = sprintf("%-*s", width, str), | |
both = sprintf("%-*s", width, sprintf("%*s", floor(width / 2), str))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: