cynkra / collector

What the Package Does (One Line, Title Case)
0 stars 0 forks source link

Error with auk package #2

Closed krlmlr closed 5 months ago

krlmlr commented 5 months ago

With a variant of https://github.com/cynkra/dplyr/pull/4 (applied on top of the most recent dplyr, our fork is hopelessly outdated):

f <- system.file("extdata/ebd-rollup-ex.txt", package = "auk")
ebd <- auk::read_ebd(f, rollup = FALSE)
auk::auk_rollup(ebd)
#> Error:
#> ℹ In argument: `count = dplyr::coalesce(.data$count, "X")`.
#> Caused by error:
#> ! unused argument (base::quote(c("Setophaga coronata", "Columba livia", "Fulica americana", "Columba livia", "Junco hyemalis", "Columba livia", "Setophaga coronata", "Colaptes auratus", "Loxia curvirostra", "Colaptes auratus")))

Created on 2024-04-18 with reprex v2.1.0

krlmlr commented 5 months ago

I also can't replay the files collected from running R CMD check with auk, with a similar error.

Will try another package.

moodymudskipper commented 5 months ago

This seems to be due to some dplyr magic :

df1 <- tibble(a="A")

# these work
mutate(df1, b = paste(a, "X"))
#> # A tibble: 1 × 2
#>   a     b    
#>   <chr> <chr>
#> 1 A     A X
coalesce(df1$a, "X")
#> [1] "A"
transform(df1, b = coalesce(a, "X"))
#>   a b
#> 1 A A

# this doesnt
mutate(df1, b = coalesce(a, "X"))
#> Error:
#> ℹ In argument: `b = coalesce(a, "X")`.
#> Caused by error:
#> ! unused argument (base::quote("A"))
#> Backtrace:
#>      ▆
#>   1. ├─dplyr::mutate(df1, b = coalesce(a, "X"))
#>   2. │ └─collector::collect_and_run()
#>   3. │   └─base::eval(call_to_original, new_caller_env) at collector/R/collector.R:116:3
#>   4. │     └─base::eval(call_to_original, new_caller_env)
#>   5. │       ├─dplyr (local) `<fn>`(df1, b = coalesce(a, "X"))
#>   6. │       └─dplyr:::mutate.data.frame(df1, b = coalesce(a, "X")) at dplyr/R/mutate.R:146:3
#>   7. │         └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by) at dplyr/R/mutate.R:181:3
#>   8. │           ├─base::withCallingHandlers(...) at dplyr/R/mutate.R:268:3
#>   9. │           └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns) at dplyr/R/mutate.R:273:7
#>  10. │             └─mask$eval_all_mutate(quo) at dplyr/R/mutate.R:380:9
#>  11. │               └─dplyr (local) eval() at dplyr/R/data-mask.R:94:7
#>  12. ├─dplyr::coalesce(a, "X")
#>  13. │ └─collector::collect_and_run()
#>  14. │   └─collector:::env_clone_lazy(caller_env) at collector/R/collector.R:104:3
#>  15. │     └─collector:::env_clone_lazy(env_parent(env)) at collector/R/collector.R:126:3
#>  16. │       └─rlang::env_bind_lazy(clone, `:=`(!!nm, !!env[[nm]])) at collector/R/collector.R:132:5
#>  17. ├─base::delayedAssign(x, value = "A", assign.env = y, eval.env = z)
#>  18. └─base::.handleSimpleError(...)
#>  19.   └─dplyr (local) h(simpleError(msg, call))
#>  20.     └─rlang::abort(message, class = error_class, parent = parent, call = error_call) at dplyr/R/conditions.R:235:5
moodymudskipper commented 5 months ago

I think it's due to a rlang bug, but one we might work around,

At some point in env_clone_lazy we do (here inlined) :

env_bind_lazy(clone, a = "A")
#> Error in (function ()  : unused argument (base::quote("A"))

if we remove the binding first (usually unneeded) this works, and it's ok to do it because at this point we're looping on evaluated variables

krlmlr commented 5 months ago

Confirming that auk now works, thanks. It is collecting too much data for its calls to n() . Leading to https://github.com/cynkra/collector/issues/9.