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

Specify n argument for dbReadTable() #25

Open
krlmlr opened this issue Apr 29, 2018 · 7 comments
Open

Specify n argument for dbReadTable() #25

krlmlr opened this issue Apr 29, 2018 · 7 comments

Comments

@krlmlr
Copy link
Member

krlmlr commented Apr 29, 2018

to limit the number of rows read.

@krlmlr
Copy link
Member Author

krlmlr commented Aug 23, 2019

The argument can't be named n because there's a conflict with name:

f <- function(name, ..., n = NULL) {
  tibble::lst(name, ..., n)
}

f("a")
#> $name
#> [1] "a"
#> 
#> $n
#> NULL
f(n = "a")
#> Error in eval_tidy(xs[[i]], unique_output): argument "name" is missing, with no default
f(name = "a")
#> $name
#> [1] "a"
#> 
#> $n
#> NULL

Created on 2019-08-23 by the reprex package (v0.3.0)

Going for max_rows and establishing consistency in r-dbi/DBI#235.

@krlmlr
Copy link
Member Author

krlmlr commented Sep 23, 2019

Scratch that: n seems perfectly fine. Still need to understand why the first implementation attempt in RSQLite failed.

f <- function(name, ..., n = NULL) {
  tibble::lst(name, ..., n)
}

f("b")
#> $name
#> [1] "b"
#> 
#> $n
#> NULL
f(n = "a")
#> Error in eval_tidy(xs[[i]], unique_output): argument "name" is missing, with no default
f("b", n = "a")
#> $name
#> [1] "b"
#> 
#> $n
#> [1] "a"
f(n = "a", "b")
#> $name
#> [1] "b"
#> 
#> $n
#> [1] "a"

Created on 2019-09-23 by the reprex package (v0.3.0)

@krlmlr
Copy link
Member Author

krlmlr commented Sep 23, 2019

The problem is partial matching of arguments for backends that don't implement the n argument yet:

library(tibble)

f <- function(name, ...) {
  lst(name, ...)
}

f(3, 1)
#> $name
#> [1] 3
#> 
#> $`1`
#> [1] 1
f(1, name = 3)
#> $name
#> [1] 3
#> 
#> $`1`
#> [1] 1

# Bad
f(1, n = 3)
#> $name
#> [1] 3
#> 
#> $`1`
#> [1] 1

Created on 2019-09-23 by the reprex package (v0.3.0)

@krlmlr
Copy link
Member Author

krlmlr commented Sep 23, 2019

Can solve by declaring the n argument before the ellipsis in the dbReadTable() generic.

@krlmlr
Copy link
Member Author

krlmlr commented Oct 13, 2019

Backends probably want to override this to include LIMIT n or TOP n in the query.

@krlmlr
Copy link
Member Author

krlmlr commented Oct 13, 2019

Postponing, because if we limit rows we also might want to limit columns. This functionality already exists in much better form in dbplyr and other packages.

@krlmlr
Copy link
Member Author

krlmlr commented Sep 6, 2021

The "first n rows" isn't usually a good criterion because the data is returned in an order decided by the server.

@krlmlr krlmlr closed this as completed Sep 6, 2021
@krlmlr krlmlr transferred this issue from r-dbi/DBI Nov 1, 2021
@krlmlr krlmlr reopened this Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant