Skip to content

Commit f2ece98

Browse files
committed
Add comment about what expansion is for
1 parent 9984791 commit f2ece98

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

R/across.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,22 @@ dplyr_quosures <- function(...) {
616616
quosures
617617
}
618618

619-
# Always guaranteed to be 1 quosure in, 1 quosure out, unlike `expand_across()`
619+
# Expand an `if_any()` or `if_all()` call
620+
#
621+
# Always guaranteed to be 1 quosure in, 1 quosure out, unlike `expand_across()`.
622+
#
623+
# For the dplyr backend, the main reason we expand at all is to evaluate
624+
# tidyselection exactly once (rather than once per group), because tidyselection
625+
# is rather slow.
626+
#
627+
# At one point we believed `if_any()` and `if_all()` could be implemented as
628+
# "pure expansion" that would run before dispatching to other backends, like
629+
# dbplyr. In theory this could expand to a chain of `&` and `|` operations that
630+
# dbplyr would already know how to translate (so dbplyr itself would not have to
631+
# know how to implement `if_any()` and `if_all()`), but in practice we need more
632+
# error checking than what `x & y & z` gets us, so we actually expand to a
633+
# vctrs-backed implementation since the "pure expansion" ideas have never played
634+
# out.
620635
expand_if_across <- function(quo) {
621636
if (quo_is_call(quo, "if_any", ns = c("", "dplyr"))) {
622637
variant <- "any"

0 commit comments

Comments
 (0)