Skip to content

v3: variable_details.csv smoking Func:: names and DerivedVar feeders out of sync with refactored R functions #185

Description

@DougManuel

Problem

inst/extdata/variable_details.csv on v3 (d98e9d6) references smoking derivation functions that do not exist in the package, so rec_with_table() fails (or silently skips) when harmonizing through the worksheet path:

Error in get(custom_function_name) : object 'calculate_SMKG040' not found
Worksheet recEnd Actual function in R/smoke-start.R
Func::calculate_SMKG040 calculate_SMKG040_cont()
Func::calculate_SMKG203_continuous calculate_SMKG203_cont()
Func::calculate_SMKG203_from_combined calculate_SMKG203_cont()
Func::calculate_SMKG207_continuous calculate_SMKG207_cont()
Func::calculate_SMKG207_from_combined calculate_SMKG207_cont()

The DerivedVar:: feeder lists in the same rows also no longer match the function signatures:

Variable (block) Worksheet feeders Function signature expects
SMKG040_cont (PUMF 2001–2003, 2005–2014) [SMKG203_pre2005, SMKG207_pre2005] / [SMKG203_2005plus, SMKG207_2005plus] (categorical) calculate_SMKG040_cont(SMKG203_cont, SMKG207_cont) (continuous midpoints)
SMKG203_cont (PUMF 2015+) [SMK_005, SMKG040] (grouped category) calculate_SMKG203_cont(SMK_005, SMKG040_cont)
SMKG207_cont (PUMF 2015+) [SMK_005, SMK_030, SMKG040] — three feeders calculate_SMKG207_cont(SMK_030, SMKG040_cont) — two parameters (third feeder lands in output_format)
SMKG207_cont / SMK_207 (Master 2015+) [SMK_005, SMK_030, SMK_040] — three feeders same two-parameter signature

Impact

  • SMKG040_cont cannot be derived for PUMF 2001–2014 or Master 2001–2014, which breaks the age_start_smoking chain through rec_with_table().
  • SMKG203_cont / SMKG207_cont (2015+) and SMK_040 / SMK_203 / SMK_207 (Master 2015+) hit the same phantom-name failure.

The test suite passes because it calls the calculate_*() functions directly with vectors; Func:: resolution from the worksheet is only exercised by an actual rec_with_table() run.

Proposed fix (validated locally)

Exact cell replacements in variable_details.csv:

  • Func::calculate_SMKG040Func::calculate_SMKG040_cont
  • Func::calculate_SMKG203_continuous and Func::calculate_SMKG203_from_combinedFunc::calculate_SMKG203_cont
  • Func::calculate_SMKG207_continuous and Func::calculate_SMKG207_from_combinedFunc::calculate_SMKG207_cont
  • DerivedVar::[SMKG203_pre2005, SMKG207_pre2005] and DerivedVar::[SMKG203_2005plus, SMKG207_2005plus]DerivedVar::[SMKG203_cont, SMKG207_cont]
  • DerivedVar::[SMK_005, SMKG040]DerivedVar::[SMK_005, SMKG040_cont]
  • DerivedVar::[SMK_005, SMK_030, SMKG040]DerivedVar::[SMK_030, SMKG040_cont]
  • DerivedVar::[SMK_005, SMK_030, SMK_040]DerivedVar::[SMK_030, SMK_040]

This matches the era design documented in calculate_SMKG040_cont() (2001–2014: combine 203/207 midpoints into 040; 2015+: derive 203/207 from directly-recoded SMKG040_cont via the SMK_005/SMK_030 gates). The packaged .rda worksheets would need rebuilding from the CSVs afterward. We have these fixes applied locally and are validating them against the CSHM (cshgm-dev) harmonization pipeline; happy to open a PR.

Context

Found while integrating cchsflow v3 into the CSHM pipeline, which passes the v3 CSV worksheets explicitly to rec_with_table().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions