purrr icon indicating copy to clipboard operation
purrr copied to clipboard

The lambda pattern ~.y(.x) fails when re-written as ~..2(..1)

Open ArtemSokolov opened this issue 4 years ago • 2 comments

My understanding is that pronouns ..1, ..2, etc. are a generalization of .x and .y for functions that operate on more than two arguments. However, I noticed that there's a discrepancy in how the two sets of pronouns behave when one of the pronouns is to be interpreted as a function in a ~ lambda:

x <- list( c(1,2), c(2,3) )
f <- list( mean, sum )

pmap( list(x,f), ~.y(.x) )    # Works
pmap( list(x,f), ~..2(..1) )  # Fails : could not find function "..2"

## Current workaround
pmap( list(x,f), ~rlang::exec(..2, ..1) )

ArtemSokolov avatar Nov 25 '20 18:11 ArtemSokolov

Looks like this is a bug in R:

f <- function(...) ..1(..2)
f(identity, 1)
#> Error in ..1(..2) : could not find function "..1"

It would probably be low priority for them or for us to fix this.

lionel- avatar Nov 25 '20 18:11 lionel-

No worries. It came up in a Stack Overflow question, so I thought I'd report it for posterity.

Thanks for the quick feedback, @lionel- . I hope you guys are doing well in this disaster of a year.

ArtemSokolov avatar Nov 25 '20 18:11 ArtemSokolov