You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider a use case where functions from collapse are invoked using qualified calls, i.e., collapse::function. This is the preferred approach if one writes another package or just wants to keep the environment clean. Now, taking an example from across:
collapse::fsummarise(collapse::wlddev, collapse::across(PCGDP:GINI, collapse::fmean, w=POP))
#> Error: 'across' is not an exported object from 'namespace:collapse'
Scenario 3: Qualified calls after exporting across
Let's modify NAMESPACE to add export(across) and rebuild collapse. This still doesn't work but the error is different:
collapse::fsummarise(collapse::wlddev, collapse::across(PCGDP:GINI, collapse::fmean, w=POP))
#> Error in collapse::across(PCGDP:GINI, collapse::fmean, w = POP) : #> across() can only work inside fmutate() and fsummarise()
This is expected because throwing an error is, in fact, all that collapse::across does. Looking into the definition of fsummarise, one can notice that the heavy lifting is actually done by do_across, and across is just a call name. Enter scenario 4.
Scenario 4: Qualified calls after replacing across with a dummy
This doesn't work, but the error is now related to fmean:
# asign a different function the same nameacross<-dplyr::acrosscollapse::fsummarise(collapse::wlddev, across(PCGDP:GINI, collapse::fmean, w=POP))
#> Error in fmean(.data_, w = POP, drop = FALSE) : #> could not find function "fmean"
So slightly modifying the above, one obtains a working solution:
What is the recommended way to call fmean and related functions? As shown above, collapse::fmean does not properly resolve.
Steps/Code to Reproduce
collapse::fsummarise(collapse::wlddev, collapse::across(PCGDP:GINI, collapse::fmean, w=POP))
#> Error: 'across' is not an exported object from 'namespace:collapse'
collapse::fsummarise(collapse::wlddev, collapse::across(PCGDP:GINI, collapse::fmean, w=POP))
#> Error: 'across' is not an exported object from 'namespace:collapse'
If exported as is:
collapse::fsummarise(collapse::wlddev, collapse::across(PCGDP:GINI, collapse::fmean, w=POP))
#> Error in collapse::across(PCGDP:GINI, collapse::fmean, w = POP) : #> across() can only work inside fmutate() and fsummarise()
Thanks, I'll see what I can do about fmean. across() is not exported because this would give a namespace conflict with dplyr. I had though about calling it facross(), but decided against it because it is unnecessary to use qualified names in this case, although I of course understand that this comes as a surprise.
Describe the bug
Consider a use case where functions from
collapse
are invoked using qualified calls, i.e.,collapse::function
. This is the preferred approach if one writes another package or just wants to keep the environment clean. Now, taking an example fromacross
:Scenario 1: Attach the package
This works:
Scenario 2: Qualified calls
This doesn't work:
Scenario 3: Qualified calls after exporting across
Let's modify
NAMESPACE
to addexport(across)
and rebuildcollapse
. This still doesn't work but the error is different:This is expected because throwing an error is, in fact, all that
collapse::across
does. Looking into the definition offsummarise
, one can notice that the heavy lifting is actually done bydo_across
, andacross
is just a call name. Enter scenario 4.Scenario 4: Qualified calls after replacing across with a dummy
This doesn't work, but the error is now related to
fmean
:So slightly modifying the above, one obtains a working solution:
In fact, defining across is not even needed:
Questions
In
dplyr
, for example, you can do both:This is possible because they check the calling environment in a different way.
While this works:
Not qualifying
across
seems odd.fmean
and related functions? As shown above,collapse::fmean
does not properly resolve.Steps/Code to Reproduce
Expected Results
Actual Results
If exported as is:
Session Info
P.S. Thank you for this useful and performant package!
The text was updated successfully, but these errors were encountered: