| scr_fetch | R Documentation |
Sampling happens on the server, not in R: pulling a million rows to
discard ninety percent of them pays the network cost twice. max_rows is
a memory guard: when it binds, the requested fraction is reduced on the
server and the reduction is reported. The random expression follows the
connection class (rand(seed) on Spark/Databricks/MySQL, random() on
PostgreSQL/DuckDB, an integer-modulo expression on SQLite, which has no
seedable random()); pass sample_expr to override it.
scr_fetch(
con,
table,
sample_frac = 1,
seed = NULL,
max_rows = NULL,
sample_expr = NULL,
verbose = NULL
)
con |
A DBI connection, from |
table |
Qualified table name. |
sample_frac |
Fraction of rows to fetch, in (0, 1]. |
seed |
Seed of the server-side random function, where supported. |
max_rows |
Row cap. |
sample_expr |
Optional SQL expression yielding a uniform number in
|
verbose |
|
A data.table with the fetched table.
Other database:
scr_connect()
con <- scr_connect(driver = RSQLite::SQLite(), dbname = ":memory:")
d <- scr_demo; d$ref_date <- as.character(d$ref_date)
DBI::dbWriteTable(con, "dtm", d)
nrow(scr_fetch(con, "dtm", sample_frac = 0.5, seed = 42))
nrow(scr_fetch(con, "dtm", max_rows = 1000))
DBI::dbDisconnect(con)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.