larry77

Untitled

Dec 31st, 2024
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. ``` r
  2. rm(list=ls())
  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: 11.
  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. library(tictoc)
  18. library(arrow)
  19. #>
  20. #> Attaching package: 'arrow'
  21. #> The following object is masked from 'package:lubridate':
  22. #>
  23. #> duration
  24. #> The following object is masked from 'package:utils':
  25. #>
  26. #> timestamp
  27.  
  28.  
  29. # Increased the size of data
  30. ## dd <- tibble(x=1:100000000, y=rep(LETTERS[1:20], 5000000))
  31.  
  32.  
  33. ## write_csv(dd, "test.csv")
  34.  
  35.  
  36. df <- duck_csv("test.csv")
  37.  
  38. system.time({
  39. df_stat <- df |>
  40. summarise(total=sum(x), .by = y) |>
  41. collect() |>
  42. as_tibble()
  43.  
  44. })
  45. #> user system elapsed
  46. #> 28.368 0.437 7.866
  47.  
  48.  
  49. df2 <- open_dataset("test.csv",
  50. format = "csv",
  51. skip_rows = 0)
  52.  
  53. system.time({
  54. df_stat2 <- df2 |>
  55. group_by(y) |>
  56. summarise(total=sum(x)) |>
  57. ungroup() |>
  58. collect()
  59.  
  60. })
  61. #> user system elapsed
  62. #> 12.319 0.352 7.477
  63.  
  64.  
  65. print("So far so good")
  66. #> [1] "So far so good"
  67. ```
  68.  
  69. <sup>Created on 2024-12-31 with [reprex v2.1.0](https://reprex.tidyverse.org)</sup>
Advertisement
Add Comment
Please, Sign In to add comment