With {magrittr}, I'd become quite accustomed (and fond of) this pattern:
df %>%
dplyr::mutate(foo = purrr::pmap(., function(...) {
do_some_stuff_with(...)
}))
The 'dot' (.
) as the first argument to pmap
references df
.
With R's base/native pipe (|>
), this pattern no longer works. The .data
pronoun also doesn't work:
## NO GOOD: . doesn't exist
df |> mutate(foo = pmap(., function(...) do_some_stuff_with(...)))
## NO GOOD: .data is only a pronoun; it doesn't refer to df here
df |> mutate(foo = pmap(.data, function(...) do_some_stuff_with(...)))
The most common way to handle this, as far as I can tell, is with an IIFE:
## SO-SO: works, but the IIFE reduces readability (a lot, IMO)
df |> (\(x) {
mutate(x, foo = pmap(x, function(...) do_some_stuff_with(...)))
})()
Is there another pattern/utility available within the {tidyverse} that helps replicate the original (more legible) pattern?