Hi thank you for your reply,
The second piece of code was expected to behave like the first piece since the code is the same but called from within purrr::map instead of from a standard function.
The drive behind the original code is that I have a large dataset from which to create different subsets based on several criteria (which I can then feed into models or diagnostic plots). To do this I generate a tibble in which each row contains the criteria to generate a specific subset of the original data. The critera are varying but not the original data, hence the choice to map over the arguments rather than the original data. This approach usually works very well for me, but I do not understand the error I am getting from rlang.
Below is a slightly more complex example which hopefully better captures what I am trying to achieve:
library(tidyverse)
df <- tibble(
## Define variables on which the data should be filtered
var = c("hp", "disp"),
## Define cutoff values for the filtering
cutoff = c(300, 400)
) %>%
group_by(var, cutoff) %>%
## Creating the data subsets
mutate(out = map2(
.x = var,
.y = cutoff,
.f = ~filter(input, .data[[.x]] > .y),
input = mtcars
)
)
#> Error in local_error_context(dots = dots, .index = i, mask = mask): promise already under evaluation: recursive default argument reference or earlier problems?
Created on 2022-08-04 by the reprex package (v2.0.1)
Of note out of this code I was expecting a list column (out) containing the corresponding subsets to be added to my tibble (df).