memdb_frame()
works like tibble::tibble()
, but instead of creating a new
data frame in R, it creates a table in src_memdb()
.
memdb_frame(..., .name = unique_table_name())
tbl_memdb(df, name = deparse(substitute(df)))
src_memdb()
<dynamic-dots
>
A set of name-value pairs. These arguments are
processed with rlang::quos()
and support unquote via !!
and
unquote-splice via !!!
. Use :=
to create columns that start with a dot.
Arguments are evaluated sequentially.
You can refer to previously created elements directly or using the .data
pronoun.
To refer explicitly to objects in the calling environment, use !!
or
.env, e.g. !!.data
or .env$.data
for the special case of an object
named .data
.
Data frame to copy
Name of table in database: defaults to a random name that's unlikely to conflict with an existing table.
library(dplyr)
df <- memdb_frame(x = runif(100), y = runif(100))
df %>% arrange(x)
#> # Source: SQL [?? x 2]
#> # Database: sqlite 3.46.0 [:memory:]
#> # Ordered by: x
#> x y
#> <dbl> <dbl>
#> 1 0.00248 0.159
#> 2 0.0137 0.851
#> 3 0.0270 0.896
#> 4 0.0386 0.690
#> 5 0.0399 0.451
#> 6 0.0511 0.412
#> 7 0.0673 0.467
#> 8 0.0859 0.483
#> 9 0.0860 0.0730
#> 10 0.0898 0.0990
#> # ℹ more rows
df %>% arrange(x) %>% show_query()
#> <SQL>
#> SELECT `dbplyr_Y1bPB7zLD3`.*
#> FROM `dbplyr_Y1bPB7zLD3`
#> ORDER BY `x`
mtcars_db <- tbl_memdb(mtcars)
mtcars_db %>% group_by(cyl) %>% summarise(n = n()) %>% show_query()
#> <SQL>
#> SELECT `cyl`, COUNT(*) AS `n`
#> FROM `mtcars`
#> GROUP BY `cyl`