Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
d55c3aa
[Feature] add papers branch to repo
wyusuf068 Jun 4, 2020
47e51c4
[Feature] edit abstract to fit 250 word limit
wyusuf068 Jun 15, 2020
ac179b0
[Feature] edits to meet 3000 word limit
wyusuf068 Jun 29, 2020
6e67834
[feature] suggested edits to abstract and intro
DougManuel Jul 6, 2020
18d56e4
[Feature] finalize structured abstract, move documents to CJPH folder
wyusuf068 Jul 7, 2020
98cc1ac
add missing contributor to abstract
wyusuf068 Jul 7, 2020
b4da005
[feature] add study size to CCHS in abstract.
DougManuel Jul 7, 2020
96eb01c
[Feature] update titlepage
wyusuf068 Jul 23, 2020
6dc3c55
[Feature] edits to paper
wyusuf068 Aug 7, 2020
b9b86a0
[Feature] minor edits to rmd
wyusuf068 Aug 11, 2020
419961f
[edits] public health practice paper - abstract and intro
DougManuel Aug 17, 2020
fb11a4c
[edits] public health practice paper - intro and background
DougManuel Aug 18, 2020
037d2a0
[edits] public health practice paper - methods
DougManuel Aug 18, 2020
743b808
[edits] public health practice paper - results
DougManuel Aug 19, 2020
784ddc9
[Feature] add figures, feedback from external reviewers
wyusuf068 Aug 20, 2020
5be3088
[edits] public health practice paper - discussion
DougManuel Aug 20, 2020
871ab87
Merge remote-tracking branch 'origin/paper-writeups' into paper-writeups
DougManuel Aug 20, 2020
b15d9dd
[feature] resolve merge conflicts
DougManuel Aug 20, 2020
1777d09
[bug] fix yml header
DougManuel Aug 20, 2020
6b51fc1
[feature] change cchsflow document image
DougManuel Aug 20, 2020
d06fc2a
[edits] public health practice paper - add roadmap to discussion
DougManuel Aug 21, 2020
936578b
[Refactor] change citation style, fix broken latex citations
wyusuf068 Aug 21, 2020
8df2bc5
[Refactor] Minor edits to center graph and remove some white space
rvyuha Aug 21, 2020
4968616
[Feature] add additional nodes
wyusuf068 Aug 21, 2020
9c77d47
[Bug] Modified end of lines
rvyuha Aug 21, 2020
7d3d0d9
[Feature] edits to text, addition of sources
wyusuf068 Aug 21, 2020
429f546
[edits] small edits throughout. References added
DougManuel Aug 21, 2020
db3fe27
Merge remote-tracking branch 'origin/paper-writeups' into paper-writeups
DougManuel Aug 21, 2020
89966d8
[Feature] add translated abstract
wyusuf068 Aug 21, 2020
4fd9634
[edits] pulbic health practice paper
DougManuel Aug 23, 2020
bbc957d
[Feature] edits to paper, edits to .bib file
wyusuf068 Aug 23, 2020
831f6b7
[Feature] final edits
wyusuf068 Aug 24, 2020
7f97c64
[feature] add French abstract and edits to public health practice paper
DougManuel Aug 24, 2020
5cc54c4
[Feature] final edits before submission
wyusuf068 Aug 26, 2020
2e7509b
[Feature] edits to paper following CJPH feedback
wyusuf068 Sep 2, 2020
34d5279
[feature] build .docx of submitted paper
DougManuel Nov 6, 2020
ca0937d
[feature] build .pdf of sumbitted paper
DougManuel Nov 6, 2020
d1c3901
[feature] 'selection of variables' edits to address reviewers comment
DougManuel Nov 6, 2020
16ab97c
[Bug] fix data pull
wyusuf068 Nov 6, 2020
74e166e
[Feature] edits to text - rmv contractions & 1st person terms
wyusuf068 Nov 9, 2020
1e97ecf
[Feature] edits to paper
wyusuf068 Dec 7, 2020
897b7bf
[feature] update abstract in CJPH paper
DougManuel Dec 12, 2020
516276b
[refactor] edits to CJPH paper
DougManuel Dec 12, 2020
01ed32b
[feature] add code link to CJPH paper
DougManuel Dec 12, 2020
065de08
[Feature] edits to cjph paper, add corrections file
wyusuf068 Dec 12, 2020
3e575cc
[feature] edits to reduce CJPH word length
DougManuel Dec 13, 2020
1cc27bd
Merge remote-tracking branch 'origin/paper-writeups' into paper-writeups
DougManuel Dec 13, 2020
426b965
[feature] Edits to the CJPH paper
DougManuel Dec 13, 2020
54d0d37
[feature] add CJPH template to papers
DougManuel Dec 13, 2020
2f6a16d
[feature] add MS Word template
DougManuel Dec 13, 2020
69326aa
[Feature] minor edits to cjph paper
wyusuf068 Dec 13, 2020
289cc40
[Feature] prepare for cjph resubmission
wyusuf068 Dec 14, 2020
9d7865b
[Bug] upload correct titlepage
wyusuf068 Dec 16, 2020
eed6791
[Feature] add author contributions
wyusuf068 Dec 17, 2020
ed18cc1
[Refactor] move author contributions to titlepage
wyusuf068 Dec 18, 2020
8dcef7d
Merge branch 'master' into paper-writeups
wyusuf068 Sep 1, 2022
3519fb9
Create folder for uRos presentation
wyusuf068 Sep 1, 2022
0e19f18
Update bibliography.bib
wyusuf068 Sep 1, 2022
7c77a80
Reword abstract
kittychenn Sep 6, 2022
c0af31e
Edit abstract
wyusuf068 Sep 8, 2022
95e5eee
uROS suggested edits
DougManuel Sep 8, 2022
7307392
Edits to text
CBjerke Sep 14, 2022
ce6cc0d
Merge pull request #120 from Big-Life-Lab/uros-presentation
DougManuel Sep 14, 2022
e969c2f
Add citation for recodeflow
wyusuf068 Sep 14, 2022
790154e
Add authorship list
wyusuf068 Sep 15, 2022
e4141b9
Merge branch 'uros-presentation' into paper-writeups
wyusuf068 Sep 15, 2022
c1574f5
ignore .Rcheck folder
yulric Sep 24, 2025
fad4761
updated DESCRIPTION file with suggested packages
yulric Sep 24, 2025
ecd54b0
added url field to pkgdown config
yulric Sep 24, 2025
279a70c
added newline to pkgdown config
yulric Sep 24, 2025
e9a68e1
updates to getting started guide
yulric Sep 24, 2025
dea1135
documentation logo fixes
yulric Sep 24, 2025
f47baff
Added new variable PACFLEI, leisure physical activity
yulric Jan 15, 2026
97b07f3
Updated PACDEE variable for the master file
yulric Jan 15, 2026
e7e94b9
Updated PAA_045 for the master file
yulric Jan 15, 2026
7b75cac
Updated PAA_050 variable for the master file
yulric Jan 15, 2026
3b30cb5
Updated PAA_075 variable for the master file
yulric Jan 15, 2026
5449d7c
Updated PAA_080 variable for the master file
yulric Jan 15, 2026
388b5f0
Updated PAADVDYS variable for the master file
yulric Jan 15, 2026
a2a2053
Updated PAADVVIG variable for the master file
yulric Jan 15, 2026
52349a7
Updated PAYDVTOA for the master file
yulric Jan 15, 2026
540fdec
Updated PAYDVADL for the master file
yulric Jan 15, 2026
fa931f5
Updated PAYDVVIG variable for the master file
yulric Jan 15, 2026
3621e67
Updated the PAYDVDYS variable for the master file
yulric Jan 15, 2026
c74e14e
Updated the energy_exp variable for the master sheet
yulric Jan 15, 2026
8a46409
Added new variable for the master file, DEN_132 last time visited den…
yulric Jan 16, 2026
7db9971
PA harmonization: fixes, 2019-2020 extension, and PAADVWHO
DougManuel Jan 19, 2026
16e063b
Add CEP-006 oral health review with PUMF integration testing
DougManuel Jan 27, 2026
b143375
Fix CSV formatting for GitHub Actions
DougManuel Jan 27, 2026
6a3f59b
Merge pull request #157 from Big-Life-Lab/v3-phys-activity
rafdoodle Feb 4, 2026
99b5c40
Added PUMF cycles, 2015-2018 DEN_035, and Ont. optional note to DEN_1…
rafdoodle Feb 4, 2026
a5f902e
Merge pull request #158 from Big-Life-Lab/v3-den-132
rafdoodle Feb 5, 2026
c46592a
Brought in Caitlin's commits from PR #149
rafdoodle Feb 5, 2026
e13f1f6
Replaced SDCGCBG_A with SDCGCB (_m and _s), and updated SDCGCBG (_p o…
rafdoodle Feb 6, 2026
d3e7b5a
Replaced SDCGRES_A with SDCDRES (_m and _s), and updated SDCGRES (_p …
rafdoodle Feb 6, 2026
5b89547
Created pct_time_fun_A function to calculate % time in Canada using M…
rafdoodle Feb 6, 2026
6260d65
Incorporated Doug's small fixes to the worksheets
rafdoodle Feb 12, 2026
ca14db3
Added missing unit tests for born-in-Canada case and pct_time_fun_cat…
rafdoodle Feb 12, 2026
2c4c9d1
Refactored pct_time_der: unified PUMF/master, added SDCGRES_cont, out…
DougManuel Feb 12, 2026
180eeb1
Replaced _s with _m for pct_time variables and re-documented updated …
rafdoodle Feb 13, 2026
6ee9336
Merge pull request #165 from Big-Life-Lab/v3-pct-time-canada
rafdoodle Feb 13, 2026
0e492e6
Replaced all NA::x with NAx in dummyVariable column of variable_details
rafdoodle Feb 13, 2026
9910462
Set dummyVariable for all Func:: rows to NA
rafdoodle Feb 13, 2026
b7b2e7f
Bringing in changes from PR #148
rafdoodle Feb 13, 2026
4548eee
Minor edits to few physical activity variables
rafdoodle Feb 14, 2026
16bf1f3
Bringing in changes from PR #170; eliminated _m fron DHHGAGE_cont
rafdoodle Feb 25, 2026
613d326
Merge pull request #174 from Big-Life-Lab/v3-demographics
rafdoodle Feb 25, 2026
54199b2
Bringing in changes from PR #169
rafdoodle Feb 25, 2026
3907d62
Bringing in changes from PR #168
rafdoodle Feb 26, 2026
34b7001
Extended energy_exp to 2019-2020 and made its function usable for Mas…
rafdoodle Mar 11, 2026
650586a
Bringing in csv changes and refactored alcohol function architecture …
rafdoodle Mar 27, 2026
8e46551
Bringing in cep from PR #166
rafdoodle Mar 27, 2026
8d59d5d
Bringing in csv changes and refactored alcohol function architecture …
rafdoodle Mar 28, 2026
d7088f5
Updated version and lastUpdated information for ADL and alcohol varia…
rafdoodle Mar 28, 2026
8ea8cfe
Renamed ADL_0X_A to ADL_0X_cat4
rafdoodle Apr 1, 2026
01462d0
Renamed DHHGAGE_X variants and DHH_MS_A
rafdoodle Apr 1, 2026
3ce9a9f
Bringing in csv changes and refactored BMI functions from PR #146
rafdoodle Apr 2, 2026
96f627b
Bringing in changes from PR #167
rafdoodle Apr 3, 2026
9e3f085
Bringing in changes from PR #176
rafdoodle Apr 7, 2026
d2c0f0c
Restored all v3 csv changes elminated by commit 96f627b
rafdoodle Apr 8, 2026
5aceb01
Properly bringing in csv changes from PRs #167 and #176
rafdoodle Apr 8, 2026
702db21
Bringing in changes from PR #171
rafdoodle Apr 10, 2026
728d98a
Repaired variable_details rows for number_conditions variable which h…
rafdoodle Apr 10, 2026
9ec705b
Ensured consistent version and lastUpdated information across csv wor…
rafdoodle Apr 10, 2026
699dbff
Bringing in changes from PR #161
rafdoodle Apr 10, 2026
1033a21
Bringing in changes from PR #160
rafdoodle Apr 11, 2026
f07fc23
Fixed SLPG01_2015plus cat1 and replaced dummyVariable NA::x with NAx …
rafdoodle Apr 11, 2026
eda1756
Extended select DHHGAGE variants to 2019-2020 and 2022 PUMF data; ren…
rafdoodle Apr 15, 2026
bd0df3a
feat(smoking): CEP-002 smoking variable harmonisation + v3 DV infrast…
rafdoodle Apr 29, 2026
d50d7aa
Ensured age and sex variables present in all 2001-2023 PUMF and Maste…
rafdoodle Apr 30, 2026
72fc0fb
Bringing in all relevant files for Yulric from PR #181
rafdoodle May 6, 2026
7407e07
Extended alcohol, chronic condition, marital status, education, gener…
rafdoodle Jun 3, 2026
7528d81
Removed 2019-2020 mappings added to wrong era-specific blocks
rafdoodle Jun 3, 2026
f91c15f
Added 2015-2020 Master harmonization for EDUDR04 with new EDUDR04_fun…
rafdoodle Jun 4, 2026
56022c5
Fixed last EHG2_04 row in variable_details.csv
rafdoodle Jun 4, 2026
d98e9d6
Added energy_exp_cat
rafdoodle Jun 4, 2026
d636573
fix(v3): regenerate NAMESPACE and repair smoking worksheet derivations
DougManuel Jun 10, 2026
e3fbf85
Cleaned csv worksheets to follow csv-conventiond.md and rebuild RData…
rafdoodle Jun 10, 2026
b7723dd
Rewrite ADL and alcohol functions onto canonical 3-step architecture
DougManuel Jun 11, 2026
63450ba
Fix list-mode rec_with_table applying first database's rules to all d…
DougManuel Jun 11, 2026
05a0f3c
Added missing PUMF data to SMKDSTY_cat3 rows in variable_details.csv
rafdoodle Jun 19, 2026
3708e39
Merge pull request #186 from Big-Life-Lab/fix/v3-smoking-worksheet-sync
rafdoodle Jun 19, 2026
df6c4f8
Added oral health variables from PR #140
rafdoodle Jun 19, 2026
5d03070
Fixed DEN_132 rows by fixing 2007-2008 typo, fixing variableStart map…
rafdoodle Jun 19, 2026
af16db7
Merge pull request #188 from Big-Life-Lab/paper-writeups
rafdoodle Jun 19, 2026
34d0636
Rebuilt variables.RData and variable_details.RData after adding oral …
rafdoodle Jun 19, 2026
484ebf7
Added papers/ to .Rbuildignore
rafdoodle Jun 19, 2026
81c596e
Bringing in updated files from v3 branch to ensure clean merge
rafdoodle Jun 22, 2026
5c2bcbd
Merge branch 'v3' into favicon-fixes
rafdoodle Jun 22, 2026
9b1f1cf
Merge pull request #144 from Big-Life-Lab/favicon-fixes
rafdoodle Jun 22, 2026
50c39d9
Brought in more updated files from PR #140
rafdoodle Jun 22, 2026
dcb33d1
Merge remote-tracking branch 'origin/v3-skills/review-validation' int…
rafdoodle Jun 22, 2026
cf6d3bc
Bringing in sedentary activity variables from PR #114
rafdoodle Jun 22, 2026
8fdc4e2
Rebuilt variables.RData and variable_details.RData after adding seden…
rafdoodle Jun 22, 2026
cfffe5f
Fixed #138 by setting all "50+ years" midpoints from 55 to 51 for all…
rafdoodle Jun 23, 2026
f72fbfd
Fixed #139 by adding "White Canadians born outside of Canada" and "No…
rafdoodle Jun 23, 2026
af925ff
Addressed #172 by cleaning dummyVariable column in variable_details.c…
rafdoodle Jun 23, 2026
52d5c0b
Addressed #178 and #179 by extending SDC ethnicity/language/migration…
rafdoodle Jun 24, 2026
f078e9d
Incorporated 3-step architecture and addressed #173 for all DemPoRTv2…
rafdoodle Jun 25, 2026
1ca5e6e
Addressed #173 by standardizing NULL handling with tagged_na("c") for…
rafdoodle Jun 25, 2026
960635c
Rebuilt variable_details.RData after renaming Func:: calls
rafdoodle Jun 26, 2026
b6270d2
Added prep_cat_output() helper, which preserves tagged NA distinction…
rafdoodle Jun 27, 2026
967be79
Consolidated validation infrastructure from Doug/Yulric feature branc…
rafdoodle Jun 29, 2026
4c22630
Refactored and upgraded COPD_Emph_der into CCC_091_der with Master co…
rafdoodle Jun 29, 2026
35db4c6
Updated NAMESPACE via roxygen (removed deleted COPD_Emph_der_fun1/fun…
rafdoodle Jun 29, 2026
0860899
Fixed NA handling in education function
rafdoodle Jun 30, 2026
ca02a94
Restructured DESCRIPTION Depends/Imports for CRAN compliance; moved h…
rafdoodle Jun 30, 2026
8171e96
Added .claude/ and ceps/ to .Rbuildignore for clean package build (re…
rafdoodle Jun 30, 2026
51c81a0
Replaced non-ASCII characters in R/missing-pattern-cache.R with ASCII…
rafdoodle Jun 30, 2026
e13cc20
Reviewed and updated roxygen documentation: fixed broken examples, re…
rafdoodle Jun 30, 2026
05421fe
Updated test assertions to match schema changes; skipped rec_with_tab…
rafdoodle Jun 30, 2026
5301929
Resolved global variable binding NOTEs for CRAN check compliance; add…
rafdoodle Jun 30, 2026
e67ef32
Fixed stale Func:: reference, standardized worksheet units and NA lab…
rafdoodle Jun 30, 2026
c1a16df
Upgraded version number to 3.0.0 on DESCRIPTION
rafdoodle Jun 30, 2026
2c99210
Further standardized worksheet units and NA labels, and clarified thi…
rafdoodle Jul 2, 2026
860167b
Standardized roxygen documentation across all 46 v3 3-step functions …
rafdoodle Jul 2, 2026
850039f
Extended ADL variables to 2019-2023 Master cycles
rafdoodle Jul 2, 2026
cb4d1a4
Updated DemPoRTv2 variables to CCHS 2022 PUMF and 2023 Master (re #189)
rafdoodle Jul 3, 2026
a666197
Extended chronic condition variables present in DemPoRTv2 to CCHS 202…
rafdoodle Jul 3, 2026
c120017
Extended other alcohol variables to CCHS 2022 PUMF and 2023 Master
rafdoodle Jul 6, 2026
921403d
Extended EDUDR03 and FVCDTOT 2022 PUMF and 2023 Master when necessary
rafdoodle Jul 6, 2026
2bd1e20
Extended all other general health (GEN) variables to CCHS 2022 PUMF a…
rafdoodle Jul 6, 2026
090bd39
Extended PAADVTRV, PAADVWHO, PAYDVTTR, and active_transport to 2021 M…
rafdoodle Jul 6, 2026
4d42e47
Extended all relevant sleep (SLP) variables to 2021 Master cycle
rafdoodle Jul 6, 2026
3ae2bb1
Extended HWTDCOR_der to 2023 Master cycle
rafdoodle Jul 6, 2026
8919910
Added missing 2023 Master coverage for certain HUI hearing and vision…
rafdoodle Jul 7, 2026
0f55035
Extended several chronic condition (CCC) variables to 2023 Master cycle
rafdoodle Jul 8, 2026
19ceb10
Extended CCCG102_2005plus to 2019-2020 PUMF cycle
rafdoodle Jul 8, 2026
4b00d17
Renamed ALCDTTM_A to ALCDTTM_former
rafdoodle Jul 8, 2026
0a66559
Extended ADM_RNO and WTS_ weight variables to all PUMF and Master cyc…
rafdoodle Jul 9, 2026
9165467
Extended DHH_OWN and DHHGHSZ past 2017-2018 and improved their coverage
rafdoodle Jul 9, 2026
1406aff
Add CEP-018 review artifacts for PR #191; fix check-csv workflow and …
DougManuel Jul 15, 2026
638de98
Add schema-driven content validation: database registry, column enums…
DougManuel Jul 15, 2026
617148c
Consume cchs_missing_data.yaml: schema-driven fallback pattern and pr…
DougManuel Jul 15, 2026
2d3c1ca
Slim cchs_missing_data.yaml to one normative encoding per fact (v1.1.0)
DougManuel Jul 15, 2026
0df245b
Fixed documentation structure for load-schema.R
rafdoodle Jul 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
^CRAN-RELEASE$
^CODE_OF_CONDUCT.md
^.github
^papers$
^\.claude$
^ceps$
^.*\.DS_Store$
182 changes: 182 additions & 0 deletions .claude/skills/cchsflow-derive/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
---
name: cchsflow-derive
description: Write and review derived variable functions for cchsflow. Use when implementing new DV functions (calculate_*, assess_*, categorize_*), upgrading existing functions to v3 architecture, reviewing DV code for correctness, or preparing DV changes for commit. Covers the 3-step architecture, source-agnostic design, quality tiers, patterns, testing, and package-level validation.
allowed-tools: Bash(Rscript:*), Bash(R:*), Bash(git:*), Read, Glob, Grep
---

# cchsflow derived variable development

Write, review, and validate derived variable functions using the v3 3-step architecture.

## Usage

```
/cchsflow-derive # general guidance (reads foundations)
/cchsflow-derive calculate_bmi # review/write a specific function
/cchsflow-derive --check # run done criteria checks
```

## Before you start

### Required reading

Before writing or reviewing a DV function, read these docs (in this skill's `docs/` folder):

1. **[foundations.md](docs/foundations.md)** — 3-step architecture, missing data handling, quality tiers, coding standards, anti-patterns. Read this first.
2. **The pattern doc** that matches your function (see "Choose a pattern" below)

### Choose a pattern

Identify which pattern your function follows, then read the corresponding doc:

| Pattern | When to use | Doc |
|---------|-------------|-----|
| **Formula calculation** | Compute a value from inputs (BMI, pack-years) | [formula-calculation.md](docs/patterns/formula-calculation.md) |
| **Category grouping** | Map values to categories (BMI categories, smoking status) | [category-grouping.md](docs/patterns/category-grouping.md) |
| **Pass-through** | Clean and forward a single variable | [pass-through.md](docs/patterns/pass-through.md) |
| **Cat-to-continuous** | Midpoint imputation from categorical ranges | [cat-to-continuous.md](docs/patterns/cat-to-continuous.md) |
| **Multi-source routing** | Choose best source with priority chain | [multi-source-routing.md](docs/patterns/multi-source-routing.md) |
| **Pathway branching** | Complex decision tree with gate variables | [pathway-branching.md](docs/patterns/pathway-branching.md) |

### Reference material

- **[7-levels.md](docs/7-levels.md)** — function complexity taxonomy (L1-L7)
- **[function-inventory.md](docs/function-inventory.md)** — all existing DV functions with pattern, level, and tier
- **[testing.md](docs/testing.md)** — unit test and golden fixture patterns, common failure diagnostics

## Development workflow

### 1. Write tests

Follow the test tier matching your function's quality tier (see [testing.md](docs/testing.md)):

- **Bronze**: Happy path + one missing input
- **Silver**: + out-of-range, vectors, dataframe via `mutate()`
- **Gold**: + every `case_when()` branch, tagged NA type verification, `output_format` parameter

### 2. Write the function

Follow the pattern template from the appropriate pattern doc. Key principles:

- **Source-agnostic**: Semantic parameter names (`height_m`, `weight_kg`), not CCHS variable names. ONE function for both PUMF and Master; the worksheet routes different source variables to the same parameters.
- **3-step**: `clean_variables(output_format = "tagged_na")` → `case_when()` logic → `clean_variables(output_format = output_format)`
- **Step 1 always uses `"tagged_na"`**: Never pass the user's `output_format` to Step 1 — `any_missing()` in Step 2 won't detect numeric missing codes.
- **Namespace-qualify**: `dplyr::case_when()`, `haven::tagged_na()` — functions must work standalone.

### 3. Write roxygen documentation

Silver and gold tier require the full template (see foundations.md § Documentation):

```r
#' @title [verb phrase]
#' @description [1-2 sentences]
#' @details [implementation notes, PUMF vs Master table if source-agnostic]
#' @param var1 [description]
#' @param output_format Output missing data format: "tagged_na" (default) or "original".
#' @param ... Arguments passed from deprecated aliases.
#' @return [type and range]
#' @examples
#' # Scalar
#' # Vector
#' # Dataframe
#' # Standalone with rec_with_table (in \dontrun{})
#' @references
#' @seealso
#' @export
```

**`@param ...` rule**: If deprecated aliases use `@rdname` pointing to your function and their signature is `function(...)`, you MUST add `@param ... Arguments passed from deprecated aliases.` to your roxygen. Otherwise R CMD check will report "Undocumented arguments in Rd file: '...'".

### 4. Write deprecated aliases (if renaming)

If the function replaces an older function name, add aliases in `R/deprecated-aliases.R`:

```r
#' @rdname new_function_name
#' @export
old_function_name <- function(...) {
.Deprecated("new_function_name",
msg = "old_function_name() is deprecated. Use new_function_name() instead.")
new_function_name(...)
}
```

### 5. Update worksheets (if needed)

If the function is referenced from `variable_details.csv` via `Func::`:

- Update `recEnd` to point to the new function name
- Update `dummyVariable` if function name changed
- Run `Rscript exec/fix-worksheets.R` after any CSV modification
- Rebuild RData if worksheet structure changed (see cchsflow-worksheets skill)

## Done criteria

**Before committing DV function changes, ALL of these must pass.** Run them in order — earlier checks are faster and catch different issues.

### Check 1: Unit tests pass

```r
# From the project root (or worktree root)
Rscript -e 'devtools::load_all(); testthat::test_file("tests/testthat/test-<domain>.R")'
```

Verify: 0 failures for in-scope tests. Pre-existing failures in other test files are acceptable (note them but don't block on them).

### Check 2: R CMD check passes

```r
# Quick check — catches NAMESPACE, roxygen, imports (skips tests/examples)
Rscript -e 'devtools::check(document = FALSE, args = "--no-tests --no-examples --no-vignettes --no-manual")'

# Full check — recommended before PR
Rscript -e 'devtools::check()'
```

Verify: 0 **new** errors/warnings/notes compared to the branch baseline. Common issues caught only here:

- Undocumented `...` from `@rdname` aliases
- Missing NAMESPACE exports
- Broken `@examples`
- Undeclared imports in DESCRIPTION

### Check 3: Worksheet validation (if worksheets changed)

Invoke the `cchsflow-validation` skill, or run manually:

```r
Rscript exec/fix-worksheets.R
```

### Check 4: Roxygen checklist

Verify manually against the template in Step 3 above:

- [ ] `@title`, `@description`, `@details` present
- [ ] All `@param` documented (including `...` if aliases exist)
- [ ] `@examples` includes scalar, vector, dataframe, and `rec_with_table()`
- [ ] `@return` describes type and range
- [ ] `@export` present
- [ ] `@seealso` links related functions

### Check 5: Test coverage checklist

- [ ] Every `case_when()` branch has a test
- [ ] Scalar, vector, and dataframe inputs tested
- [ ] Missing inputs tested (NA, tagged_na("a"), tagged_na("b"))
- [ ] Boundary values tested (for categorization functions)
- [ ] Deprecated aliases tested (expect deprecation warning + correct delegation)

## Cross-references

### Related cchsflow skills

- **cchsflow-review** — PR review of worksheet changes (L0-L6 process). Lives on `skills/review-validation` branch.
- **cchsflow-validation** — programmatic worksheet validation. Lives on `skills/review-validation` branch.
- **cchsflow-worksheets** — worksheet authoring guidance. Lives on `skills/review-validation` branch.

### External references

- R CMD check guidance: `~/github/ai-infrastructure/context/domains/r_packages.md` § "Local verification before committing"
- V3 coding standards: project memory `project_derive_function_standards.md`
- Reference implementations: `bmi_fun()` in `R/bmi.R` (formula), `pack_years_fun()` in `R/smoking.R` (complex)
115 changes: 115 additions & 0 deletions .claude/skills/cchsflow-derive/docs/7-levels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Function levels (L1-L7)

A taxonomy of reusable function complexity. Higher levels compose lower
levels. Understanding the level helps you write the right amount of code
and reuse existing infrastructure.

## Level definitions

| Level | Name | Purpose | Example |
|-------|------|---------|---------|
| L1 | Foundational utility | Low-level missing data, cleaning, pattern detection | `any_missing()`, `clean_variables()`, `assign_missing()` |
| L2 | Midpoint mapping | Convert categorical ranges to continuous values via lookup table | `smkg_age_midpoint()` |
| L3 | Single-source pass-through | Wrap and clean a single input, worksheet handles routing | `calculate_age_start_smoking()` |
| L4 | Categorical-to-continuous conversion | Apply midpoint imputation with domain logic | `calculate_SMK_06A_cont()` |
| L5 | Filter/route by status | Extract subset of input based on status filtering | `calculate_SMKG203_cont()`, `assess_quit_pathway()` |
| L6 | Multi-source combining | Route multiple sources with priority hierarchy | `calculate_time_quit_smoking_complete()` |
| L7 | Complex multi-source unification | Full decision tree combining multiple inputs | `calculate_SMKDSTY_cat6()`, `calculate_pack_years()` |

## Decision tree

Use this to classify your function:

```
Does your function just pass through a single source?
→ YES → L3 (pass-through)
→ NO ↓

Does it convert categories to continuous values?
→ YES, using a lookup table only → L2 (midpoint mapping)
→ YES, with domain logic → L4 (cat-to-continuous)
→ NO ↓

Does it filter/extract based on a status variable?
→ YES, single source filtered by status → L5 (filter/route)
→ NO ↓

Does it combine multiple sources with priority?
→ YES, with pathway-aware routing → L6 (combining)
→ NO ↓

Does it have a complex decision tree with multiple inputs?
→ YES → L7 (complex unification)
```

## How levels compose

Pack-years demonstrates the full stack:

```
calculate_pack_years (L7)
├── clean_variables() (L1)
├── any_missing() + get_priority_missing() (L1)
├── SMKDSTY_A (L7: calculate_SMKDSTY_cat6)
├── age_start_smoking (L3: calculate_age_start_smoking)
│ └── derive_passthrough() (L1)
├── time_quit_smoking (L6: calculate_time_quit_smoking_complete)
│ ├── calculate_SMK_06A_cont() (L4)
│ │ └── smkg_age_midpoint() (L2)
│ └── pathway logic with SMK_10_gate (L5: assess_quit_pathway)
├── cigs_per_day (L7: calculate_cigs_per_day)
│ └── status-based routing (L5 pattern)
└── age (L3: via worksheet routing)
```

## Level-by-level guidance

### L1: Foundational utilities

These are shared infrastructure. You rarely write new L1 functions — you
use them. Key functions to know:

- `clean_variables(vars, variable_details, output_format)` — step 1 and 3
- `any_missing(var1, var2, ...)` — vectorised missing detection
- `get_priority_missing(var1, var2, ...)` — NA::b wins over NA::a
- `assign_missing(type, var_name, variable_details)` — create typed missing
- `derive_passthrough(value, variable_name, variable_details, output_format)` — L3 helper

### L2: Midpoint mapping

A lookup table that converts categorical codes to continuous values.
Typically a simple named vector or small helper function.

```r
smkg_age_midpoint <- function(category) {
midpoints <- c(8, 13, 16, 18.5, 22, 27, 32, 37, 42, 47, 55)
midpoints[category]
}
```

### L3: Single-source pass-through

Minimal wrapper around `derive_passthrough()`. The worksheet handles
which source variable to feed in.

```r
calculate_age_start_smoking <- function(
age_start_smoking, variable_details = NULL, output_format = "tagged_na") {
derive_passthrough(age_start_smoking, "age_start_smoking",
variable_details, output_format)
}
```

### L4-L7: See pattern docs

These levels correspond to specific patterns:

- L4 → `patterns/cat-to-continuous.md`
- L5 → `patterns/multi-source-routing.md` (filter variant)
- L6 → `patterns/multi-source-routing.md` or `patterns/pathway-branching.md`
- L7 → `patterns/formula-calculation.md` or `patterns/category-grouping.md`

## Existing function inventory

See `function-inventory.md` for a complete mapping of all current DV
functions to their levels and patterns.
Loading
Loading