etiennebacher / tidypolars

Get the power of polars with the syntax of the tidyverse
https://tidypolars.etiennebacher.com
Other
141 stars 3 forks source link

Add a custom class for `tidypolars` #84

Closed etiennebacher closed 4 months ago

etiennebacher commented 5 months ago

https://github.com/pola-rs/r-polars/issues/759

Make a tidypolars class so that I can have my own print methods and more stuff. I don't want the user to have to do an extra step so maybe each of my functions could have a reconstruct_tidypolars_output() at the end that automatically adds the class. Sort of what dplyr does with some functions:

library(dplyr, warn.conflicts = FALSE)

mtcars |> 
  group_by(cyl) |> 
  class()
#> [1] "grouped_df" "tbl_df"     "tbl"        "data.frame"

Or maybe just keep as_polars() and rename it as_tidypolars()? But then I would also have to run this after scanning/reading a file with polars.

eitsupi commented 4 months ago

I recommend that you look into the implementation of the arrow package. For example: https://github.com/apache/arrow/blob/d9891918a42c74002533ed5c06c42b7d0d070820/r/R/dplyr-filter.R#L21-L86

It works simply by having the return value of the S3 methods be the class.

filter.ArrowTabular returns arrow_dplyr_query filter.arrow_dplyr_query returns arrow_dplyr_query ...