This can be used in pipelines that pass data back and forth between Arrow and DuckDB.
Details
Note that you can only call collect() or compute() on the result of this
function once. To work around this limitation, you should either only call
collect() as the final step in a pipeline or call as_arrow_table() on the
result to materialize the entire Table in-memory.
Examples
library(dplyr)
ds <- InMemoryDataset$create(mtcars)
ds |>
filter(mpg < 30) |>
to_duckdb() |>
group_by(cyl) |>
summarize(mean_mpg = mean(mpg, na.rm = TRUE)) |>
to_arrow() |>
collect()
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> i /tmp/Rtmpjg3Ig8/duckdb
#> This is removed when the R session ends.
#> * Extensions are re-downloaded each session.
#> * Secrets are lost.
#> i Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> i Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> i See ?duckdb_storage for details and alternatives.
#> # A tibble: 3 x 2
#> cyl mean_mpg
#> <dbl> <dbl>
#> 1 4 23.7
#> 2 6 19.7
#> 3 8 15.1