Repository navigation
Plan seq_along() and length() of a string column - #466
Merged
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ADR 0107 plans
seq_along(x)in a groupedmutate()andlength(x)in a grouped summary,reframe()ormutate()when x is a Stata numeric column. A string column kept the group loop, even after #465 split it into its groups in one native call. Over the 42,739 women in the first 100,000 rows of the India 2021 DHS births file,mutate(b, k = seq_along(caseid), .by = caseid)took about 0.39 seconds.This PR lets the plans take x when its first chunk is a Stata string with the classes the package gives one,
c("dta_string", "vctrs_vctr", "character"), or a character vector without a class. Each later chunk must have the first chunk's classes, the group's size, and a form whose length runs no R code: an ordinary vector or one of the package's owned, compact or metadata proxy strings. ADR 0130 records the details.Behavior
Values, attributes, ALTREP forms, warnings and errors are unchanged. R dispatches
length()for a Stata string, so the plan declines when R would find alength()method for one of its classes, or a default one, from the call's environment or in base's table, and when a column is named for one, as ADR 0107 requires for a Stata numeric. A string column with other classes keeps the loop.As in ADR 0107, the plan does not prove what it skips, so a traced or replaced
mask$with_group()orrlang::eval_tidy()no longer sees a planned expression's later groups.Timing
Best of three runs in fresh R sessions, in seconds, with the builds interleaved. Before is main at c91ca74, which has #465.
mutate(b, k = seq_along(caseid), .by = caseid)summarise(b, k = length(caseid), .by = caseid)mutate(b, k = length(caseid), .by = caseid)Most of what remains is the split of the column, which the plan reads to check the chunks.
Tests
test-summary-plan.Rcompares 4 calls with the group loop and counts the planned expressions:seq_along()andlength()of a Stata string and of a character vector inmutate()andsummarise(), aftergroup_by(), and of a compact string a read gives.length()method fordta_string,vctrs_vctrorcharacter, each callingNextMethod(), keeps the loop, and so does a column of another class.