Skip to content

slice helper error when no n or prop #6361

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

Closed
eutwt opened this issue Jul 25, 2022 · 1 comment · Fixed by #6378
Closed

slice helper error when no n or prop #6361

eutwt opened this issue Jul 25, 2022 · 1 comment · Fixed by #6378
Labels
feature a feature request or enhancement rows ↕️ Operations on rows: filter(), slice(), arrange()

Comments

@eutwt
Copy link
Contributor

eutwt commented Jul 25, 2022

For the slice helper functions, would it make sense to move check_slice_dots() from the data.frame methods to the generics? My thought is that dtplyr and dbplyr can rely on it to prevent malformed calls and provide the right error. Right now when n is not provided, dtplyr has an error message that's not as friendly, and dbplyr has different behavior.

library(rlang)
library(glue)
#> Warning: package 'glue' was built under R version 4.1.2
df <- data.frame(a = 1:10)

library(dplyr, warn.conflicts = FALSE)
#> Warning: package 'dplyr' was built under R version 4.1.2

df %>% 
  slice_sample(1)
#> Error in `slice_sample()`:
#> ! `n` must be explicitly named.
#> ℹ Did you mean `slice_sample(n = 1)`?

library(dtplyr)
#> Warning: package 'dtplyr' was built under R version 4.1.2

df %>% 
  lazy_dt() %>% 
  slice_sample(1)
#> Error in `slice_sample()`:
#> ! `...` must be empty.
#> ✖ Problematic argument:
#> • ..1 = 1
#> ℹ Did you forget to name an argument?

library(dbplyr, warn.conflicts = FALSE)
#> Warning: package 'dbplyr' was built under R version 4.1.2

con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
copy_to(con, df)
df2 <- tbl(con, "df")

df2 %>% 
  slice_sample(1)
#> # Source:   SQL [1 x 1]
#> # Database: sqlite 3.38.5 [:memory:]
#>       a
#>   <int>
#> 1     6

Created on 2022-07-24 by the reprex package (v2.0.1)

@hadley
Copy link
Member

hadley commented Jul 25, 2022

I'm not sure whether or not it's a good idea to put input checking code in the generic or not. My main concern is that this fundamentally limited the scope of the methods. But maybe that's ok here, since we expect methods to always require one of n and prop?

@hadley hadley added feature a feature request or enhancement rows ↕️ Operations on rows: filter(), slice(), arrange() labels Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement rows ↕️ Operations on rows: filter(), slice(), arrange()
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants