Calling as_survey_design() on data that has been grouped with group_by() silently drops the groups. This can lead to unexpected results. For example, in the following reprex one might expect the two results to be equal, but only one row is returned in the second example because group_by() is called before as_survey_design().
as_survey_design() gave a warning if called with grouped data, or
as_survey_design() had an as_survey_design.grouped_df() method that preserved grouping.
I think preserving grouping would be the most user friendly, but giving a warning could also work if preserving grouping isn't feasible. I can work on a PR to implement either solution if it would be helpful!
Calling
as_survey_design()
on data that has been grouped withgroup_by()
silently drops the groups. This can lead to unexpected results. For example, in the following reprex one might expect the two results to be equal, but only one row is returned in the second example becausegroup_by()
is called beforeas_survey_design()
.Created on 2024-08-14 with reprex v2.1.0
It would be great if either
as_survey_design()
gave a warning if called with grouped data, oras_survey_design()
had anas_survey_design.grouped_df()
method that preserved grouping.I think preserving grouping would be the most user friendly, but giving a warning could also work if preserving grouping isn't feasible. I can work on a PR to implement either solution if it would be helpful!