Skip to content

Migrate some simple ddply() calls to dplyr equivalents#1388

Open
MichaelChirico wants to merge 8 commits intotopepo:masterfrom
MichaelChirico:ddply-1
Open

Migrate some simple ddply() calls to dplyr equivalents#1388
MichaelChirico wants to merge 8 commits intotopepo:masterfrom
MichaelChirico:ddply-1

Conversation

@MichaelChirico
Copy link
Copy Markdown
Contributor

@MichaelChirico MichaelChirico commented Jun 3, 2025

Closes #1387.

Similar to #1382, #1383, #1385, #1386 -- the end goal is moving away from {plyr}. Like #1386, this bumps {dplyr} from Suggests to Imports.

There are a variety of stylistic choices around using tidyverse code in a package (whether to use %>% / |>, whether to use the .data mask to avoid the need for globalVariables(), etc). Let me know your preferences and I can make further edits.

Also like #1386, the key driver of potential differences in these between {plyr} and {dplyr} comes down to the differences between plyr::rbind.fill() and dplyr::bind_rows(). Since the structure across groups in summarize() expressions is typically consistent, I don't have much concern about that here.

The second major difference is that plyr::ddply() always sorts the output by the grouping key, whereas dplyr::summarize() sorts according to the input row order (this in turn matches the {data.table} behavior). I tried to have a look at nearby code to see if the output order matters -- if it's not clear we can ignore the row ordering, I default to assuming it's important, thus we might be able to drop more arrange() calls.

There are still a large number of ddply() calls -- this reduces the number from roughly 74 to roughly 48. The remaining ones either do more complicated things around column selection, or use a much more complicated .fun which requires more careful examination. More PR(s) to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typo bug: 'rm.na' --> 'na.rm'

1 participant