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
Students often forget pipes. I wonder if we could make clearer errors in that case. The error for arrange is particularly inscrutable:
library(tidyverse)
diamonds %>%
group_by(cut) %>%
summarize(n= n())
arrange(desc(n))
#> Warning in is.na(x): is.na() applied to non-(list or vector) of type 'closure'#> Error in x[!nas]: object of type 'closure' is not subsettable
The other possible errors in this pipeline are also confusing (no applicable method for 'group_by' applied to an object of class "function" and Error: n() must only be used inside dplyr verbs.)
The errors in this particular pipeline could be improved somewhat by adding an informational group_by.default, tweaking the logic around the existing n() error, and some additional type-checking in desc. ggplot has some nice messaging like "Did you use %>% instead of +?".
arrange<-function(.data, ..., .by_group=FALSE) {
.data<- impose(.data, "arrange")
UseMethod("arrange")
}
impose<-function(.data, .fn) {
withCallingHandlers(.data, error=function(e) {
abort(c(
glue("Error when evaluating `{.fn}(.data=)`."),
i="This might to be a missing pipe."
), parent=e)
})
}
This'd give something like this:
[master*] 226.48 MB > arrange(desc(n))
Error:
Error when evaluating `arrange(.data=)`.
ℹ This might to be a missing pipe.
Caused by error in `[`:
object of type 'closure' is not subsettable
Run `rlang::last_error()` to see where the error occurred.
Warning message:
In is.na(x) : is.na() applied to non-(list or vector) of type 'closure'
but we did rule it out in #4127. Or perhaps this is a variant of UseMethod() that enforces object to be greedy ?
library(dplyr, warn.conflicts=FALSE)
xtfrm(n)
#> Warning in is.na(x): is.na() applied to non-(list or vector) of type 'closure'#> Error in x[!nas]: object of type 'closure' is not subsettable
We could fix this either by adding some additional type checks to desc() or by maybe switching from xtrfm() to vctrs::vec_proxy_order(), but it doesn't have quite the behaviour we're looking for either:
Students often forget pipes. I wonder if we could make clearer errors in that case. The error for
arrange
is particularly inscrutable:Created on 2021-09-23 by the reprex package (v2.0.1)
The other possible errors in this pipeline are also confusing (
no applicable method for 'group_by' applied to an object of class "function"
andError:
n()must only be used inside dplyr verbs.
)The errors in this particular pipeline could be improved somewhat by adding an informational
group_by.default
, tweaking the logic around the existingn()
error, and some additional type-checking indesc
.ggplot
has some nice messaging like"Did you use %>% instead of +?"
.Vaguely related: #4127
The text was updated successfully, but these errors were encountered: