Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group_by_prepare with default error_call argument results in error #6442

Closed
eutwt opened this issue Sep 1, 2022 · 1 comment
Closed

group_by_prepare with default error_call argument results in error #6442

eutwt opened this issue Sep 1, 2022 · 1 comment

Comments

@eutwt
Copy link
Contributor

eutwt commented Sep 1, 2022

The default values for arguments caller_env and error_call in group_by_prepare don't seem to work

group_by_prepare with default error_call

df <- data.frame(x = 1)
dplyr::group_by_prepare(df)
#> Error in is_missing(call): promise already under evaluation: recursive default argument reference or earlier problems?

Created on 2022-08-31 with reprex v2.0.2

with error_call supplied but not caller_env, adding a column

df <- data.frame(x = 1)
dplyr::group_by_prepare(df, y = 3, error_call = call('fun'))
#> Error in initialize(...): promise already under evaluation: recursive default argument reference or earlier problems?

Created on 2022-08-31 with reprex v2.0.2

The reason I noticed this is that group_by_prepare(data.frame(x = 1)) works with CRAN dplyr but not dev dplyr, which causes group_by to fail in dtplyr if dev dplyr is installed.

It seems to be because caller_env is self-referencing in the function signature. I guess the users of this function would be package developers who can probably figure out what's going on and just supply the arguments, but it was a little confusing. Maybe these arguments could have no default to make the error more understandable (argument "caller_env" is missing rather than promise already under evaluation), or caller_env renamed to .caller_env.

dplyr/R/group-by.r

Lines 193 to 199 in 48431a5

group_by_prepare <- function(.data,
...,
caller_env = caller_env(2),
.add = FALSE,
.dots = deprecated(),
add = deprecated(),
error_call = caller_env()) {

fun <- function(caller_env = caller_env(2)) {
  print(caller_env)
}
fun()
#> Error in print(caller_env): promise already under evaluation: recursive default argument reference or earlier problems?

Created on 2022-08-31 with reprex v2.0.2

@hadley
Copy link
Member

hadley commented Sep 13, 2022

Ended up accidentally fixing this in #6444.

@hadley hadley closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants