grantmcdermott / duckdb-polars

Introduction to DuckDB and Polars
https://grantmcdermott.com/duckdb-polars
12 stars 5 forks source link

update dplyr across syntax and add multiple summary functions #2

Open joshuafayallen opened 2 months ago

joshuafayallen commented 2 months ago

Hi Grant, Thanks for the awesome workshop! I added some updates to the dplyr::across syntax to eliminate some of the warnings.

grantmcdermott commented 1 month ago

Thanks @joshuafayallen, great to hear you found it useful. I have a bunch of changes that I want to make to the website when I get time, so will hold off merging your PR for now. Also, I don’t think you need the lambda syntax for known functions like mean with the latest dplyr. At least, that’s what I see from the docs, and I also don’t get a warning on my system.

joshuafayallen commented 1 month ago

Sorry for the late response! I lost wifi for a few weeks. I checked and I realized the reason dplyr it will only warn you if you pass additional arguments like na.rm = TRUE when you use across.



penguins |>
  group_by(species, island) |>
  summarize(
    across(c(bill_length_mm, bill_depth_mm), mean, na.rm = TRUE)
  )
#> Warning: There was 1 warning in `summarize()`.
#> ℹ In argument: `across(c(bill_length_mm, bill_depth_mm), mean, na.rm = TRUE)`.
#> ℹ In group 1: `species = Adelie` and `island = Biscoe`.
#> Caused by warning:
#> ! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
#> Supply arguments directly to `.fns` through an anonymous function instead.
#> 
#>   # Previously
#>   across(a:b, mean, na.rm = TRUE)
#> 
#>   # Now
#>   across(a:b, \(x) mean(x, na.rm = TRUE))
#> `summarise()` has grouped output by 'species'. You can override using the

penguins |> 
  group_by(species, island) |>
  summarize(
    across(c(bill_length_mm, bill_depth_mm),\(x) mean(x, na.rm = TRUE))
  )
#> `summarise()` has grouped output by 'species'. You can override using the

<sup>Created on 2024-06-06 with [reprex v2.1.0](https://reprex.tidyverse.org)</sup>