larry77

Untitled

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