Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- library(duckplyr)
- #> The duckplyr package is configured to fall back to dplyr when it encounters an
- #> incompatibility. Fallback events can be collected and uploaded for analysis to
- #> guide future development. By default, data will be collected but no data will
- #> be uploaded.
- #> ℹ Automatic fallback uploading is not controlled and therefore disabled, see
- #> `?duckplyr::fallback()`.
- #> ✔ Number of reports ready for upload: 9.
- #> → Review with `duckplyr::fallback_review()`, upload with
- #> `duckplyr::fallback_upload()`.
- #> ℹ Configure automatic uploading with `duckplyr::fallback_config()`.
- #> ✔ Overwriting dplyr methods with duckplyr methods.
- #> ℹ Turn off with `duckplyr::methods_restore()`.
- dd <- tibble(x=1:100, y=rep(LETTERS[1:20], 5))
- write_csv(dd, "test.csv")
- ## open file without reading it into memory and perform aggregations
- df <- duck_file("test.csv", "read_csv")
- df_stat <- df |>
- group_by(y) |>
- summarise(total=sum(x))
- #> Error: Materialization is disabled, use collect() or as_tibble() to materialize
- ungroup()
- #> Error in UseMethod("ungroup"): no applicable method for 'ungroup' applied to an object of class "NULL"
- df_stat2 <- df |>
- collect() |>
- group_by(y) |>
- summarise(total=sum(x))
- ungroup()
- #> Error in UseMethod("ungroup"): no applicable method for 'ungroup' applied to an object of class "NULL"
- df_stat2
- #> # A tibble: 20 × 2
- #> y total
- #> <chr> <dbl>
- #> 1 A 205
- #> 2 B 210
- #> 3 C 215
- #> 4 D 220
- #> 5 E 225
- #> 6 F 230
- #> 7 G 235
- #> 8 H 240
- #> 9 I 245
- #> 10 J 250
- #> 11 K 255
- #> 12 L 260
- #> 13 M 265
- #> 14 N 270
- #> 15 O 275
- #> 16 P 280
- #> 17 Q 285
- #> 18 R 290
- #> 19 S 295
- #> 20 T 300
- sessionInfo()
- #> R version 4.4.2 (2024-10-31)
- #> Platform: x86_64-pc-linux-gnu
- #> Running under: Debian GNU/Linux 12 (bookworm)
- #>
- #> Matrix products: default
- #> BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.11.0
- #> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0
- #>
- #> locale:
- #> [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
- #> [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
- #> [5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
- #> [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
- #> [9] LC_ADDRESS=C LC_TELEPHONE=C
- #> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
- #>
- #> time zone: Europe/Brussels
- #> tzcode source: system (glibc)
- #>
- #> attached base packages:
- #> [1] stats graphics grDevices utils datasets methods base
- #>
- #> other attached packages:
- #> [1] duckplyr_0.99.99.9910 lubridate_1.9.3 forcats_1.0.0
- #> [4] stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2
- #> [7] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
- #> [10] ggplot2_3.5.1 tidyverse_2.0.0
- #>
- #> loaded via a namespace (and not attached):
- #> [1] styler_1.10.3 utf8_1.2.4 generics_0.1.3 stringi_1.8.4
- #> [5] hms_1.1.3 digest_0.6.35 magrittr_2.0.3 evaluate_0.23
- #> [9] grid_4.4.2 timechange_0.3.0 fastmap_1.1.1 jsonlite_1.8.8
- #> [13] R.oo_1.26.0 R.cache_0.16.0 R.utils_2.12.3 DBI_1.2.2
- #> [17] scales_1.3.0 collections_0.3.7 duckdb_1.1.3-1 cli_3.6.3
- #> [21] rlang_1.1.4 crayon_1.5.2 R.methodsS3_1.8.2 bit64_4.0.5
- #> [25] munsell_0.5.1 reprex_2.1.0 withr_3.0.0 cachem_1.0.8
- #> [29] yaml_2.3.8 tools_4.4.2 parallel_4.4.2 tzdb_0.4.0
- #> [33] memoise_2.0.1 colorspace_2.1-0 vctrs_0.6.5 R6_2.5.1
- #> [37] lifecycle_1.0.4 fs_1.6.4 bit_4.0.5 vroom_1.6.5
- #> [41] pkgconfig_2.0.3 pillar_1.10.1.9000 gtable_0.3.5 glue_1.7.0
- #> [45] xfun_0.43 tidyselect_1.2.1 knitr_1.46 htmltools_0.5.8.1
- #> [49] rmarkdown_2.26 compiler_4.4.2
- Created on 2024-12-31 with reprex v2.1.0
Advertisement
Add Comment
Please, Sign In to add comment