Update plot.means_by_group.R to keep order of categories#451
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes a double assignment typo and converts the Category column to a factor in plot.means_by_group.R. The reviewer noted that using as.factor() will sort the categories alphabetically, potentially losing their original order. They suggested explicitly setting the factor levels using unique(trimmed$Category) to preserve the original order and drop unused levels.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
Please see the Gemini suggestion, as |
That was fixed when I made the comment. I'm not sure exactly what is going on with the diff and the comments but that change was made previously (which is why I only explained why I didn't add the unique(). |
|
No, there's also a second |
It's literally a one line proposed change (2 if you count fixing the duplication in the prior line). There is not a second as.factor() and actually as.factor() strangely does not have levels as an argument so you can't even do that! Therefore my one line suggestion uses The So that's another reason why checking for duplicates is redundant. Also because |
Found the as.factor.
|
I think I found what you were talking about. |
|
Thanks! Vac you also please add a |
If you really want to take the performance hit despite what I explained about how it is impossible for there to be duplicates. But what will happen if there are duplicates? I haven't tested that but what's ggplot going to do with that? Maybe if there are duplicates the names shoul be changed.? so e.g. check for duplicates |
|
If you have more than one variable in |
Done and added basic tests. |
Add tests.
|
Now you committed the I don't think we need the check for the length if we use if (length(trimmed$Category) == length(unique(trimmed$Category))) {
trimmed$Category <- factor(trimmed$Category, levels = trimmed$Category)
} else {
stop("Duplicate category names are present.")
} |
|
The commit just needs trimmed$Category <- factor(
trimmed$Category,
levels = unique(trimmed$Category)
) |
No description provided.