Repository navigation
Plan shifts whose default picks from the column - #467
Merged
Merged
Conversation
# Conflicts: # r-package/dtatools/NEWS.md # r-package/dtatools/tools/native-test-manifest.json
|
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 0088 plans
lag()andlead()of a Stata numeric column with a literal default, alone and as operands, and ADR 0119 builds such operands from the columns' rows. A default that picks from the shifted column, as inx - lag(x, default = first(x)), kept the group loop. Over the 42,739 women in the first 100,000 rows of the India 2021 DHS births file,mutate(b, k = b3 - lag(b3, default = first(b3)), .by = caseid)took about 4.3 seconds, where a tibble takes about 0.81.This PR lets the admissions take a default, tagged
defaultor untagged after n, that calls dplyr'sfirst(),last()ornth()with the shifted column as its first, untagged argument. The pick must pass ADR 0073's admission, and its closures join those R checks are not being debugged. The plans fill the positions a shift leaves with each group's value at the pick's position, or a missing value past either end, as the loop's cast of the pick does. ADR 0127 records the details.Behavior
Values, attributes, ALTREP forms, warnings and errors are unchanged. The plan declines a pick of another column, whose cast would change the value's storage, a pick ADR 0073's plan declines, another function named
first,lastornthwhere R finds it first, and a column named for one. As ADR 0097 requires of a pick, a group whose chunk has the position where the first group's chunk does not keeps the loop. A value that an old file wrote and the storage no longer takes keeps the loop, as for the shifted values.As in ADR 0074 and ADR 0088, the plans do not prove what they skip, so a traced or replaced
mask$evaluate(),rlang::eval_tidy(),.cast_to_dta()or other package helper of the loop 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 7ad6e9c.
mutate(b, k = b3 - lag(b3, default = first(b3)), .by = caseid)mutate(b, k = lag(b3, default = first(b3)), .by = caseid)mutate(b, k = lead(b11, default = last(b11)) - b11, .by = caseid)Tests
test-summary-plan.Rcompares 8mutate()calls and 6 operands with the group loop and counts the planned expressions. They cover each compact storage, labels, missing and tagged missing values, shifts as long as a group, a result a later plan reads,nth()from either end and the first group's missing position.first(), a column namedlastand an old file's values, and that debuggingfirst(),nth(),shift_c(),vec_check_size()or the package's cast and type methods keeps the loop.