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
I had a bug in my code where I'd forgotten to pass a data frame to summarize, and the resulting error message led me in the wrong direction. Here's an example:
dplyr::summarize(n=dplyr::n())
#> Error in `dplyr::n()`:#> ! Must only be used inside data-masking verbs like `mutate()`, `filter()`, and `group_by()`.
Even though the bug here is that I forgot to specify the .data argument in summarize(), with that error message I thought I was somehow using n() incorrectly.
Note that the problem seems in part due to n() being a zero-argument function. Since it doesn't take any variables, it can't refer to any variables when erroring. In contrast, the following code gives a more helpful error message:
dplyr::summarize(mean= mean(x))
#> Error: object 'x' not found
Could the error message in the first example be improved? More generally, could dplyr functions check that .data is specified and give an appropriate error message if not?