repChar.RdSimple constructors of a constant character string from one character, notably a “blank” string of given string length.
M.M. is now ‘mentally deprecating’ bl.string in
favor of using repChar() in all cases.
With R 3.3.0 (May 2016), the new function
strrep() was introduced; it is faster typically, and more
flexible, e.g. accepting a vector for the 2nd argument.
This (for now informally) deprecates all uses of repChar() and bl.string().
repChar(char, no)
bl.string(no)One string, i.e., character(1)), for bl.string a
blank string, fulfilling n == nchar(bl.string(n)).
r <- sapply(0:8, function(n) ccat(repChar(" ",n), n))
cbind(r)
#> r
#> [1,] "0"
#> [2,] " 1"
#> [3,] " 2"
#> [4,] " 3"
#> [5,] " 4"
#> [6,] " 5"
#> [7,] " 6"
#> [8,] " 7"
#> [9,] " 8"
repChar("-", 4)
#> [1] "----"
repChar("_", 6)
#> [1] "______"
## it may make sense to a string of more than one character:
repChar("-=- ", 6)
#> [1] "-=- -=- -=- -=- -=- -=- "
## show the very simple function definitions:
repChar
#> function (char, no)
#> paste(rep.int(char, no), collapse = "")
#> <bytecode: 0x55dd112ae9f0>
#> <environment: namespace:sfsmisc>
bl.string
#> function (no)
#> sprintf("%*s", no, "")
#> <bytecode: 0x55dd106e19d0>
#> <environment: namespace:sfsmisc>