This is a convenient way of generating sample data. It works similarly to
replicate(..., simplify = FALSE)
.
rerun(.n, ...)
.n | Number of times to run expressions |
---|---|
... | Expressions to re-run. |
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)
.
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).
#> [[1]] #> [1] 1.48643701 0.74245965 -0.02958559 -1.40699491 1.09164048 #> #> [[2]] #> [1] -1.0385714 -1.3429057 -0.7959764 2.1244429 -0.5499333 #> #> [[3]] #> [1] 1.99479777 -0.37637955 1.57523440 -0.02104012 -2.15554360 #> #> [[4]] #> [1] 1.3795233 -0.1293130 2.2500494 0.8972059 -1.2189534 #> #> [[5]] #> [1] 0.2176338 0.1120140 -0.9150514 -1.1933988 0.8365308 #> #> [[6]] #> [1] 1.4909572 -1.7275138 0.3668783 0.1306008 -1.0811151 #> #> [[7]] #> [1] -1.6264912 0.6093191 -0.3837559 0.2647067 -1.0759165 #> #> [[8]] #> [1] -1.7049200 -0.0900827 0.2846788 -0.4430617 -0.2991162 #> #> [[9]] #> [1] -0.7739517 0.2410810 -0.3375843 1.2491336 0.7086719 #> #> [[10]] #> [1] 1.3185074 3.4585513 -0.1949492 0.4287486 -1.4925215 #>#> [1] 0.5839396 -0.3419190 -0.8133030 -0.6915704 -0.6448143 0.7800958 #> [7] -0.3354932 0.4527590 0.6328682 0.8522864