Skip to content

Commit

Permalink
Improve str_dup documentaiton
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Dec 1, 2009
1 parent c8ea566 commit 3b0a581
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions R/dup.r
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#' Duplicate strings within a character vector.
#' Duplicate and concatenate strings within a character vector.
#'
#' Vectorised over \code{string} and \code{times}.
#'
#' @param string input character vector
#' @param times number of times to duplicate each string
#' @return character vector
#' @keywords internal
#' @keywords character
#' @examples
#' fruit <- c("apple", "pear", "banana")
#' str_dup(fruit, 2)
#' str_dup(fruit, 1:3)
#' str_c("ba", str_dup("na", 0:5))
str_dup <- function(string, times) {
string <- check_string(string)

# rep_matrix <- matrix(rep(string, times = times), nrow = times)
strings <- mlply(cbind(x = string, times), rep.int)
output <- unlist(llply(strings, str_c, collapse = ""))

Expand Down

0 comments on commit 3b0a581

Please sign in to comment.