Re-clean only the subjects whose data changed since a previous
cleangrowth run, and reuse the earlier cleaned results for
everyone else. This is intended for workflows that repeatedly clean a mostly
unchanging dataset – for example a simulation loop that perturbs a subset of
subjects and re-cleans – where a full re-run would waste most of its work.
Arguments
- new_data
A long-format
data.frame/data.tableof the current data, using growthcleanr's canonical column names (subjid,param,agedays,sex,measurement) plus a per-rowid.- cached_output
The
data.tablereturned by a previouscleangrowth()run on the earlier version of this dataset.- changed_subjids
Required. A vector of
subjidvalues whose data changed sincecached_outputwas produced and must be re-cleaned. Any subject present innew_databut not incached_output(added) is re-cleaned automatically; any subject incached_outputbut not innew_data(removed) is dropped. May be length 0 (re-clean only added subjects, if any). Values not present innew_dataare ignored.- ...
Passed verbatim to the inner
cleangrowthcall on the changed subset (e.g.checkpoint_dir,checkpoint_size,batch_size,cf_rescue, output switches). Must match the options used to producecached_output.
Value
A data.table with the same columns as cleangrowth()
would return under the same ..., containing every subject in
new_data, ordered by id.
Details
gc_partial_run() is a thin wrapper: it slices new_data down to
the changed (and any newly added) subjects, hands that subset to a single
ordinary cleangrowth() call, and row-binds the freshly cleaned rows to
the retained rows of cached_output. All arguments in ... –
including checkpoint_dir, checkpoint_size, batch_size, and
every output-column switch – are forwarded verbatim to that inner
cleangrowth() call, so a large changed subset can still be
checkpointed. The cache itself is never passed into cleangrowth();
the merge happens entirely at the output level.
Why the result is correct. After reference-based recentering,
growthcleanr cleans each subject independently of every other subject, so
cleaning only the changed subjects yields the exact same rows those subjects
would receive in a full run. The combined result is therefore identical to
cleangrowth(new_data, ...) for a given set of options (see Examples).
Caller responsibilities.
...must specify the same options used to producecached_output(samecf_rescue, permissiveness, output switches, etc.). If the requested output columns differ from those incached_output, the function stops rather than silently produceNA-filled rows.idmust be present and unique per row in bothnew_dataandcached_output, and must be stable across runs (the same measurement keeps the sameid).idis how retained cached rows and freshly cleaned rows are ordered in the output.Input must be long format (one measurement per row). Wide and semi-wide input are not supported by this wrapper.
Examples
# \donttest{
# Baseline clean of the full dataset
baseline <- cleangrowth(syngrowth)
#> [15:40:00] growthcleanr: cleaning in progress — 2,697 subjects, 77,721 measurements, 1 batch of up to 5,000 subjects
#> ************************************************************
#> growthcleanr cleaning summary (77,721 measurements)
#> Weight : 33,631 included (78.2%), 9,348 excluded (21.8%)
#> Height : 26,318 included (75.8%), 8,424 excluded (24.2%)
#> Set aside : 0 (0.0%)
#> ************************************************************
# Suppose one subject's data was corrected; re-clean only that subject
changed <- syngrowth$subjid[1]
updated <- gc_partial_run(syngrowth, baseline, changed_subjids = changed)
#> [15:42:02] growthcleanr: cleaning in progress — 1 subjects, 26 measurements, 1 batch of up to 5,000 subjects
#> ************************************************************
#> growthcleanr cleaning summary (26 measurements)
#> Weight : 10 included (71.4%), 4 excluded (28.6%)
#> Height : 10 included (83.3%), 2 excluded (16.7%)
#> Set aside : 0 (0.0%)
#> ************************************************************
# Identical to a full re-run (same options), for every subject
full <- cleangrowth(syngrowth)
#> [15:42:04] growthcleanr: cleaning in progress — 2,697 subjects, 77,721 measurements, 1 batch of up to 5,000 subjects
#> ************************************************************
#> growthcleanr cleaning summary (77,721 measurements)
#> Weight : 33,631 included (78.2%), 9,348 excluded (21.8%)
#> Height : 26,318 included (75.8%), 8,424 excluded (24.2%)
#> Set aside : 0 (0.0%)
#> ************************************************************
identical(updated[order(id)]$exclude, full[order(id)]$exclude)
#> [1] TRUE
# }
