
Append newly arrived data to a tbl_now
update.tbl_now.RdSurveillance data does not arrive once; it arrives every week. update()
takes a tbl_now and a batch of newer rows – as another tbl_now or as a
plain data.frame – and returns a single object containing both, still
knowing everything the original knew about itself.
It also moves now forward, because the new rows may carry a later report
than the object had seen. That is the difference between this and
dplyr::bind_rows(), which would give you back a plain data frame with no
idea what a nowcast is.
Usage
# S3 method for class 'tbl_now'
update(
object,
...,
new_data,
strata = "left",
covariates = strata,
t_effects = strata,
now = NULL,
remove_duplicates = NULL
)Arguments
- object
A
tbl_nowobject- ...
Additional arguments to pass to
tbl_now- new_data
Another
tbl_nowwith the samestrata,covariates,is_censored_report, andtemporal_effectsor adata.framewith additional (newer) data not present inx- strata
(optional) Whether to keep the strata from
object("left"), fromnew_data("right") or fromboth("both")- covariates
(optional) Whether to keep the covariates from
object("left"), fromnew_data("right") or fromboth("both")- t_effects
(optional) Which temporal-effects spec to keep: from
object("left", the default), fromnew_data("right") or the union of both ("both").- now
(optional) Date or
NULL(default). The date that is considered thenowof the nowcast. If nonowis given then the function automatically uses the lastevent_date.- remove_duplicates
Whether to remove duplicated rows from data (only applies for
countdata)
Note
By default it keeps the strata, covariates and temporal effects of object. Use
the strata, covariates and t_effects arguments to change it.
See also
update_now() to move now without adding rows;
tbl_now() for the attributes that are carried over;
add() and change() to edit those attributes instead of the data.
Examples
data(denguedat)
# Pretend the first 500 rows are what you had last week ...
initial_tbl <- tbl_now(denguedat[1:500, ],
event_date = "onset_week",
report_date = "report_week", strata = "gender",
verbose = FALSE
)
nrow(initial_tbl)
#> [1] 500
get_now(initial_tbl)
#> [1] "1990-09-03"
# ... and these arrived since.
new_rows <- denguedat[501:1000, ]
# The result has both, keeps `gender` as a stratum, and has moved `now`
# forward to the latest report it has now seen.
updated <- update(initial_tbl, new_data = new_rows)
nrow(updated)
#> [1] 1000
get_strata(updated)
#> [1] "gender"
get_now(updated)
#> [1] "1990-11-12"