Skip to content

Confusing error when forgetting to pipe input (i.e., first arg isn't a dataframe) #6028

@kcarnold

Description

@kcarnold

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementrows ↕️Operations on rows: filter(), slice(), arrange()vctrs ↗️

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions