Repeat the contents of character strings a given number of times.
Arguments
- strings
A character vector, where each element of the vector is a character string.
- times
The number of times each string should be repeated.
- separator
A string to place in-between each repetition of the main string.
Value
A character vector the length of whichever is longest out of strings
,
times
and separator
, where the shorter vectors will be recycled.
Each element in the result contains the same character sequence of the corresponding element in strings, repeated the given number of times.
See also
Base strrep()
which this function wraps.
Examples
str_repeat("hello")
#> [1] "hellohello"
str_repeat("hello", 3)
#> [1] "hellohellohello"
str_repeat("hello", 3, ", ")
#> [1] "hello, hello, hello"
str_repeat(c("hello", "world"))
#> [1] "hellohello" "worldworld"
str_repeat(c("hello", "world"), c(3, 1))
#> [1] "hellohellohello" "world"
str_repeat(".", 0:3)
#> [1] "" "." ".." "..."