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
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" 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 +?".
Vaguely related: #4127
Students often forget pipes. I wonder if we could make clearer errors in that case. The error for
arrangeis 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.ggplothas some nice messaging like"Did you use %>% instead of +?".Vaguely related: #4127