This is a convenient way of generating sample data. It works similarly to replicate(..., simplify = FALSE).

rerun(.n, ...)

## Arguments

.n Number of times to run expressions Expressions to re-run.

## Value

A list of length .n. Each element of ... will be re-run once for each .n.

There is one special case: if there's a single unnamed input, the second level list will be dropped. In this case, rerun(n, x) behaves like replicate(n, x, simplify = FALSE).

## Lifecycle

rerun() is in the questioning lifecycle stage because we are no longer convinced NSE functions are a good fit for purrr. Also, rerun(n, x) can just as easily be expressed as map(1:n, ~ x) (with the added benefit of being passed the current index as argument to the lambda).

## Examples

10 %>% rerun(rnorm(5))#> [[1]]
#> [1] -0.06956080  0.51562199  1.39296654  1.01856317  0.05301056
#>
#> [[2]]
#> [1]  0.5802748 -0.5941795 -0.3718553 -1.4230352 -1.1404838
#>
#> [[3]]
#> [1]  1.2685047 -0.2801044  0.9110540  2.0043945  0.2471404
#>
#> [[4]]
#> [1] -0.4290761 -2.1837551 -0.1236349  0.2873839 -0.3715993
#>
#> [[5]]
#> [1]  1.6265623  0.3099083 -1.5640407 -1.2306235 -1.3701975
#>
#> [[6]]
#> [1]  0.1065558 -0.3988255 -0.3534061  0.2345011  1.7697899
#>
#> [[7]]
#> [1]  0.45787638  1.14375811 -1.30772262 -0.94254960 -0.09496125
#>
#> [[8]]
#> [1] -1.130047 -1.456208 -1.698718 -1.240827 -1.058299
#>
#> [[9]]
#> [1] -0.75437857 -0.58510694  0.55814208 -0.01900658 -0.16935602
#>
#> [[10]]
#> [1]  1.295331 -1.426060  1.754104 -2.115575  1.009702
#> 10 %>%
rerun(x = rnorm(5), y = rnorm(5)) %>%
map_dbl(~ cor(.x$x, .x$y))#>  [1]  0.002596342  0.673652978  0.261856431  0.270511553 -0.566697593
#>  [6] -0.591663103  0.564532598  0.005869156 -0.064905322 -0.079221444