Skip to content

Fix attribute ordering in as_case_data() to match test snapshots#200

Merged
sschildhauer merged 3 commits intocopilot/fix-as-case-data-bugfrom
copilot/sub-pr-199
Apr 22, 2026
Merged

Fix attribute ordering in as_case_data() to match test snapshots#200
sschildhauer merged 3 commits intocopilot/fix-as-case-data-bugfrom
copilot/sub-pr-199

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

When input data already carries custom attributes (e.g. output of sim_case_data()), tibble::as_tibble() reorders the attribute list and pushes class to the end. The test snapshot expects class to precede the custom attributes (id_var, biomarker_var, timeindays, value_var), causing consistent snapshot failures.

Changes

  • Strip inherited custom attributes before re-adding them, using a loop over the known attribute names
  • Set class first via class(result) <- union("case_data", class(data)) to anchor it in the correct position
  • Re-add custom attributes in order: id_var (via serocalculator::set_id_var()), then biomarker_var, timeindays, value_var

This replaces the previous structure() call at the end of the pipe, which could not override attribute positions already established by as_tibble().

# Before: as_tibble() on a case_data object pushes `class` to the end
# names(attributes(result))
# [1] "names"         "id_var"        "biomarker_var" "timeindays"    "value_var"     "class"

# After: explicit ordering ensures class appears before custom attrs
# [1] "names"         "class"         "id_var"        "biomarker_var" "timeindays"    "value_var"

Copilot AI and others added 2 commits April 21, 2026 13:13
Copilot AI changed the title [WIP] Fix bug in as_case_data to ensure tests pass Fix attribute ordering in as_case_data() to match test snapshots Apr 21, 2026
Copilot AI requested a review from sschildhauer April 21, 2026 13:15
Copy link
Copy Markdown
Collaborator

@sschildhauer sschildhauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@sschildhauer sschildhauer marked this pull request as ready for review April 22, 2026 08:19
@sschildhauer sschildhauer merged commit 68c0380 into copilot/fix-as-case-data-bug Apr 22, 2026
@sschildhauer sschildhauer deleted the copilot/sub-pr-199 branch April 22, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants