1#' Right justify a string.
2#'
3#' Return \code{str} right justified in a string of length \code{width}.
4#' Padding is done using the specified \code{fillchar} (default is an ASCII space).
5#' The original string is returned if \code{width} is less than or equal to \code{nchar(str)}.
6#'
7#' @param str A character vector.
8#' @param width An integer.
9#' @param fillchar A character string.
10#'
11#' @return A character vector.
12#'
13#' @references \url{https://docs.python.org/3/library/stdtypes.html#str.rjust}
14#'
15#' @seealso \code{\link{pystr_ljust}}
16#'
17#' @examples
18#' pystr_rjust("right", 10)
19#' pystr_rjust("right", 10, "*")
20#'
21#' @export
22pystr_rjust <- function(str, width, fillchar=" ") {
23  return(vapply(str, function(x) pystr_rjust_(x, width, fillchar=fillchar), character(1), USE.NAMES = FALSE))
24}
25
26pystr_rjust_ <- function(str, width, fillchar) {
27  if(width <= nchar(str)) {
28    return(str)
29  }
30
31  return(paste0(paste(rep(fillchar, width - nchar(str)), collapse=""), str))
32}
33