Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

row_number() produces error when calling with namespace (dplyr::) in filter() #3309

Closed
jimvine opened this issue Jan 18, 2018 · 6 comments
Closed
Labels

Comments

@jimvine
Copy link
Contributor

@jimvine jimvine commented Jan 18, 2018

I would expect dplyr::row_number() to give the same output as I get with row_number(). But if I use it within filter() I get the expected results if I use the plain version but an error if I use the namespaced version.

# Repex:
# This works fine:
filter(mtcars, row_number() == 6L)

# This gives an error:
filter(mtcars, dplyr::row_number() == 6L)
# Error in filter_impl(.data, quo) : 
#   Evaluation error: argument "x" is missing, with no default.
@batpigandme
Copy link
Member

@batpigandme batpigandme commented Jan 18, 2018

If you're trying to select a row by position, the dplyr verb you want is slice:

suppressPackageStartupMessages(library(dplyr))

slice(mtcars, 6)
#> # A tibble: 1 x 11
#>     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1  18.1  6.00   225   105  2.76  3.46  20.2  1.00     0  3.00  1.00

Created on 2018-01-18 by the reprex package (v0.1.1.9000).

@jimvine
Copy link
Contributor Author

@jimvine jimvine commented Jan 18, 2018

@batpigandme I simplified for the repex to generate the error, but I'm actually trying to selectively drop rows, so my actual use case is more akin to:

filter(mtcars, row_number() != 6L)

(As in the positive row selection case, this works with row_names() but fails with dplyr::row_names().)

I'm not sure whether that's possible with slice(). This doesn't work:

slice(mtcars, !6)

@hadley
Copy link
Member

@hadley hadley commented Jan 18, 2018

You want slice(mtcars, -6)

But I wanted to solicit this issue because it suggests there's a problem with the hybrid evaluation not recognising calls of the form dplyr::

@jimvine
Copy link
Contributor Author

@jimvine jimvine commented Jan 18, 2018

@hadley That's very helpful - many thanks. Would that be worth mentioning the use of negative row values to drop in the ?slice documentation? If so, would it be helpful for me to add that as an issue, or submitting a PR?

@hadley
Copy link
Member

@hadley hadley commented Jan 18, 2018

@jimvine a PR would be awesome - the docs for slice() are pretty terrible right now

romainfrancois pushed a commit that referenced this issue Mar 14, 2018
hybrid evaluation simplifies dplyr::foo to foo. closes #3309
krlmlr added a commit that referenced this issue Mar 16, 2018
* Show clear error message for bad arguments to `funs()` (#3368).

* Improved documentation for `funs()` (#3094).

* Compute variable names for joins in R (#3430).

* Hybrid evaluation simplifies `dplyr::foo` to `foo` (#3309).

* `bind_cols()` handles unnamed list (#3402).
@lock
Copy link

@lock lock bot commented Sep 10, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Sep 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants