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 is keeping downloaded extensions in a temporary directory:
#> i /tmp/Rtmpt79zcV/duckdb/extensions
#> This is removed when the R session ends, so extensions are re-downloaded each session.
#> i To keep them, point `options(duckdb.extension_directory =)` or the `DUCKDB_EXTENSION_DIRECTORY` environment variable at a permanent path.
#> # A tibble: 3 x 2
#> cyl mean_mpg
#> <dbl> <dbl>
#> 1 6 19.7
#> 2 8 15.1
#> 3 4 23.7