Learn R Programming

DIZutils (version 0.0.12)

rep2: Repeat something with the ability to also collapse the output.

Description

Repeat something with the ability to also collapse the output. The base `rep("ha", 3)` function does not support arguments like `collapse` or `sep` like `paste(...)`. `rep2` closes this gap.

Usage

rep2(x, n, ...)

Arguments

x

The object to repeat

n

The amount how often the object should be repeated

...

Further arguments passed to `paste` (see `help("paste")` for more information).

Value

The result from `paste(rep(x, n), sep = sep, collapse = collapse)`

Examples

Run this code
# NOT RUN {
  ## rep2 is the same like rep:
  rep(x = "ha", 3)
  #> "ha" "ha" "ha"
  DIZutils::rep2(x = "ha", 3)
  #> "ha" "ha" "ha"

  ## ... but you can also use the arguments from `paste`:
  DIZutils::rep2(x = "ha", n = 3, collapse = "")
  #> "hahaha"

# }

Run the code above in your browser using DataLab