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() fails in the some corner cases #3454

Closed
vpanfilov opened this issue Mar 21, 2018 · 5 comments
Closed

row_number() fails in the some corner cases #3454

vpanfilov opened this issue Mar 21, 2018 · 5 comments
Assignees
Labels

Comments

@vpanfilov
Copy link

@vpanfilov vpanfilov commented Mar 21, 2018

row_number() windowed function fails in the corner case with 0x0 tibble:

library(tidyverse)

tibble() %>% mutate(a = row_number())
#> Error in mutate_impl(.data, dots) :
#>   Evaluation error: argument "x" is missing, with no default.

UPD: Found another misleading behaviour:

library(tidyverse)

tibble(a = 1) %>%
  mutate(b = row_number())
#> # A tibble: 1 x 2
#>       a     b
#>   <dbl> <int>
#> 1    1.     1

tibble(a = 1) %>%
  mutate(b = dplyr::row_number())
#> Error in mutate_impl(.data, dots) : 
#>   Evaluation error: argument "x" is missing, with no default.
@batpigandme
Copy link
Member

@batpigandme batpigandme commented Mar 21, 2018

What about using:

suppressPackageStartupMessages(library(dplyr))
tibble::tibble() %>% tibble::rowid_to_column("a")
#> # A tibble: 0 x 1
#> # ... with 1 variable: a <int>

Created on 2018-03-21 by the reprex package (v0.2.0).

@vpanfilov vpanfilov changed the title row_number() fails with 0x0 tibble row_number() fails in the some corner cases Mar 22, 2018
@vpanfilov
Copy link
Author

@vpanfilov vpanfilov commented Mar 22, 2018

@batpigandme, thanks! Will use rowid_to_column in my code.

Added another misleading behaviour of the row_number() to the first post.

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Mar 23, 2018

Thanks. The second example does work in the dev version of dplyr:

library(tidyverse)

tibble() %>%
  mutate(b = dplyr::row_number())
#> Error in mutate_impl(.data, dots): Evaluation error: argument "x" is missing, with no default.

tibble(a = integer()) %>%
  mutate(b = dplyr::row_number())
#> # A tibble: 0 x 2
#> # ... with 2 variables: a <int>, b <int>

tibble(a = 1) %>%
  mutate(b = dplyr::row_number())
#> # A tibble: 1 x 2
#>       a     b
#>   <dbl> <int>
#> 1    1.     1

Created on 2018-03-23 by the reprex package (v0.2.0).

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Mar 25, 2018

@romainfrancois: Can you please take a look? The first example in my last post with the empty tibble should still work.

@romainfrancois romainfrancois self-assigned this Mar 26, 2018
@krlmlr krlmlr closed this in 71b8b54 Mar 26, 2018
krlmlr added a commit that referenced this issue Mar 26, 2018
- `row_number()` works on empty subsets (#3454).
@lock
Copy link

@lock lock bot commented Sep 22, 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 22, 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
4 participants