nathaneastwood / poorman

A poor man's dependency free grammar of data manipulation
https://nathaneastwood.github.io/poorman/
Other
340 stars 15 forks source link

`group_by` doesn't work with tibbles #97

Closed etiennebacher closed 2 years ago

etiennebacher commented 2 years ago

Describe the bug When I use poorman::group_by on a tibble, it has an error:

#> Warning in xtfrm.data.frame(x): cannot xtfrm data frames
#> Warning in Ops.factor(xi, xj): '>' not meaningful for factors
#> Error in if (xi > xj) 1L else -1L: missing value where TRUE/FALSE needed

This doesn't happen with dplyr::group_by. poorman::group_by works well with dataframes.

To Reproduce

iris <- dplyr::as_tibble(iris)

dplyr::group_by(iris, Species)
#> # A tibble: 150 × 5
#> # Groups:   Species [3]
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>           <dbl>       <dbl>        <dbl>       <dbl> <fct>  
#>  1          5.1         3.5          1.4         0.2 setosa 
#>  2          4.9         3            1.4         0.2 setosa 
#>  3          4.7         3.2          1.3         0.2 setosa 
#>  4          4.6         3.1          1.5         0.2 setosa 
#>  5          5           3.6          1.4         0.2 setosa 
#>  6          5.4         3.9          1.7         0.4 setosa 
#>  7          4.6         3.4          1.4         0.3 setosa 
#>  8          5           3.4          1.5         0.2 setosa 
#>  9          4.4         2.9          1.4         0.2 setosa 
#> 10          4.9         3.1          1.5         0.1 setosa 
#> # … with 140 more rows
poorman::group_by(iris, Species)
#> Warning in xtfrm.data.frame(x): cannot xtfrm data frames
#> Warning in Ops.factor(xi, xj): '>' not meaningful for factors
#> Error in if (xi > xj) 1L else -1L: missing value where TRUE/FALSE needed

Created on 2022-05-30 by the reprex package (v2.0.1)

Expected behavior /

System Information: Please detail the following information

Additional context I normally don't use poorman but I came across a situation where this error happened. I don't know if poorman is supposed to work with tibbles all the time but since other functions (filter, etc.) work with them, I supposed this is a bug.

nathaneastwood commented 2 years ago

Thanks for pointing this out. Generally, poorman is not designed to work with tibbles. It goes against the ethos of poorman which is to use as few dependencies as possible and therefore poorman is designed to work strictly with data.frames. Are you able to provide me with more information as to how you came across this given that you don't usually work with poorman?

etiennebacher commented 2 years ago

I noticed it in a PR for easystats: https://github.com/easystats/easystats/pull/227. I came across this error and I first thought it was because of poorman::full_join (which is why I ended up using datawizard::data_join) but I noticed later that it was related to poorman::group_by.

Glad to know this is not really a bug :) This package is a great idea and has worked almost perfectly the few times I used it. The only reason I don't use it more often is that I usually end up using some other packages from the tidyverse that import most dplyr deps anyway so there's no real incentives to switch to poorman for me.

nathaneastwood commented 2 years ago

That makes sense. Thanks for the report regardless. I'm planning to soon add more to poorman but finding the time is the issue.