Skip to content

Fix max-age clade splitting in as_daisie_datatable()#61

Merged
joshwlambert merged 4 commits into
masterfrom
fix-multi-max-age-cols
May 15, 2026
Merged

Fix max-age clade splitting in as_daisie_datatable()#61
joshwlambert merged 4 commits into
masterfrom
fix-multi-max-age-cols

Conversation

@joshwlambert

Copy link
Copy Markdown
Owner

This PR addresses #60.

A as_daisie_datatable() bug mishandled island colonists with branching times older than island_age in two ways:

  1. The splitting loop's exit condition (while (brts[1] >= island_age)) never re-evaluated, so it relied on the loop body emptying event_times to break. Every event in event_times — including the colonisation time and valid in-island branching times — was emitted as its own *_MaxAge singleton row.
  2. The colonisation time at event_times[1] was being written into the first split row, producing a Branching_times value older than island_age for that singleton (the symptom reported in Bug in as_daisie_datatable() when branching times older than island age #60).

Changes

For an island colonist where one or more branching times exceed island_age:

  • each over-island branching time is split off as its own *_MaxAge singleton row, with the clade name suffixed _1, _2, ...;
  • the colonisation time, together with any branching times younger than island_age (i.e. valid in-island cladogenesis), stays as the main *_MaxAge row under the original clade name.

If every branching time exceeds island_age, the main row contains just the colonisation time. Numeric clamping to island_age - epss continues to happen in create_daisie_data(), as before.

  • Switched the splitting loop to walk event_times[2] so the colonisation time at index 1 is preserved.
  • Re-evaluated the loop condition each iteration (event_times[2] >= island_age), guarded by length(event_times) >= 2 so the loop exits cleanly once only the col_time remains.
  • Re-flag the leftover main row as *_MaxAge when its largest event still exceeds island_age.
  • Added a @details section documenting the _MaxAge splitting semantics.
  • tests/testthat/test-as_daisie_datatable.R: updated three existing test expectations to reflect the corrected splitting; and added a regression test using the exact reproducer from Bug in as_daisie_datatable() when branching times older than island age #60.
    • NEWS.md: bug-fix entry under the development version section.

@joshwlambert joshwlambert added the bug Something isn't working label May 15, 2026
@joshwlambert joshwlambert merged commit 475b088 into master May 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant