memdb_frame()
works like tibble::tibble()
, but instead of creating a new
data frame in R, it creates a table in src_memdb()
.
Usage
memdb_frame(..., .name = unique_table_name())
tbl_memdb(df, name = deparse(substitute(df)))
src_memdb()
Arguments
- ...
<
dynamic-dots
> A set of name-value pairs. These arguments are processed withrlang::quos()
and support unquote viarlang::!!
and unquote-splice viarlang::!!!
. Use:=
to create columns that start with a dot.Arguments are evaluated sequentially. You can refer to previously created elements directly or using the rlang::.data pronoun. To refer explicitly to objects in the calling environment, use
rlang::!!
or rlang::.env, e.g.!!.data
or.env$.data
for the special case of an object named.data
.- df
Data frame to copy
- name, .name
Name of table in database: defaults to a random name that's unlikely to conflict with an existing table.
Examples
library(dplyr)
df <- memdb_frame(x = runif(100), y = runif(100))
df %>% arrange(x)
#> # Source: SQL [?? x 2]
#> # Database: sqlite 3.50.4 [:memory:]
#> # Ordered by: x
#> x y
#> <dbl> <dbl>
#> 1 0.0110 0.270
#> 2 0.0372 0.996
#> 3 0.0478 0.614
#> 4 0.0587 0.171
#> 5 0.0626 0.0612
#> 6 0.0743 0.344
#> 7 0.0805 0.400
#> 8 0.0939 0.886
#> 9 0.100 0.502
#> 10 0.150 0.918
#> # ℹ more rows
df %>% arrange(x) %>% show_query()
#> <SQL>
#> SELECT `dbplyr_aByGT89T45`.*
#> FROM `dbplyr_aByGT89T45`
#> 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`