Merges one-time data (non-longitudinal) into the main skeleton data structure. This function is used for adding data that doesn't change over time, such as demographic information or baseline characteristics.
Value
The skeleton data.table is modified by reference with one-time data merged in. A column of data that already exists in skeleton is overwritten. Each person found in data gets the incoming value. Each person absent from data keeps the existing skeleton value.
The function also returns the skeleton, invisibly. The return is the object the caller passed, while that object has a free column slot for every new column. Past that point data.table cannot grow the column list in place, so the new columns land on the returned table alone. A caller that passes an expression rather than a variable MUST use the return value.
Any other name that pointed at the same table before the call is stale afterwards. R cannot grow a list in place. A growth therefore leaves the caller's binding on a NEW object, and every other name on the old one. Take an alias after the call, never before it.
See also
create_skeleton for creating the skeleton structure,
add_annual for annual data,
make_lowercase_names for data preprocessing
Other data_integration:
add_annual(),
add_cancer_without_morphology(),
add_cods(),
add_diagnoses(),
add_operations(),
add_quality_registry(),
add_rx()
Examples
# Load fake data
data("fake_person_ids", package = "swereg")
data("fake_demographics", package = "swereg")
swereg::make_lowercase_names(fake_demographics)
#> Found potential date columns: fodelseman. Consider adding them to date_columns parameter for automatic date parsing.
# Create skeleton
skeleton <- create_skeleton(fake_person_ids[1:5], 2020, "2020-53")
# Add demographic data
add_onetime(skeleton, fake_demographics, "lopnr")
# Check added variables
names(skeleton)
#> [1] "id" "isoyear" "isoyearweek" "is_isoyear"
#> [5] "isoyearweeksun" "personyears" "fodelseman" "doddatum"
