rerun: Re-run expressions multiple times

View source: R/deprec-rerun.R

rerunR Documentation

Re-run expressions multiple times

Description

[Deprecated]

This function was deprecated in purrr 1.0.0 because we believe that NSE functions are not a good fit for purrr. Also, rerun(n, x) can just as easily be expressed as ⁠map(1:n, \(i) x)⁠

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

Usage

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).

Examples

# old
5 |> rerun(rnorm(5)) |> str()
# new
1:5 |> map(\(i) rnorm(5)) |> str()

# old
5 |>
  rerun(x = rnorm(5), y = rnorm(5)) |>
  map_dbl(\(l) cor(l$x, l$y))
# new
1:5 |>
  map(\(i) list(x = rnorm(5), y = rnorm(5))) |>
  map_dbl(\(l) cor(l$x, l$y))

purrr documentation built on Aug. 10, 2023, 9:08 a.m.