tsostarics / contrastable

Contrast Coding Utilities
https://tsostarics.github.io/contrastable/
Other
0 stars 0 forks source link

Error when applying contrasts to grouping variable in `grouped_df` #8

Closed tsostarics closed 11 months ago

tsostarics commented 2 years ago
library(contrastable)
data.frame(v1 = c('a','b','c')) |> 
  dplyr::group_by(v1) |> 
  contrastable::enlist_contrasts(v1 ~ treatment_code)

Converting to factors: v1
Error in `dplyr::mutate()`:
! Problem while computing `..1 = dplyr::across(dplyr::all_of(which_to_factors), factor)`.
ℹ The error occurred in group 0: character(0).
Caused by error in `across()`:
! Can't subset columns that don't exist.
✖ Column `v1` doesn't exist.

Error from the internal mutate call comes from attempting to set contrasts on a grouping column in a dataframe. Options to fix:

tsostarics commented 11 months ago

Revisiting this, it seems like dropping the dplyr implementation a while ago inadvertently fixed this.