1#' @title Backport of strrep for R < 3.3.0 2#' @rdname strrep 3#' 4#' @description 5#' See the original description in \code{base::strrep}. 6#' 7#' @keywords internal 8#' @rawNamespace if (getRversion() < "3.3.0") export(strrep) 9#' @examples 10#' # get function from namespace instead of possibly getting 11#' # implementation shipped with recent R versions: 12#' bp_strrep = getFromNamespace("strrep", "backports") 13#' 14#' bp_strrep("-", 10) 15strrep = function(x, times) { 16 x = as.character(x) 17 if (length(x) == 0L) 18 return(x) 19 unlist(.mapply(function(x, times) { 20 if (is.na(x) || is.na(times)) 21 return(NA_character_) 22 if (times <= 0L) 23 return("") 24 paste0(replicate(times, x), collapse = "") 25 }, list(x = x, times = times), MoreArgs = list()), use.names = FALSE) 26} 27