Skip to content

Fix species_params<-() diff for list, matrix and object columns#465

Merged
gustavdelius merged 1 commit into
masterfrom
fix-species-params-list-column-diff
Jul 21, 2026
Merged

Fix species_params<-() diff for list, matrix and object columns#465
gustavdelius merged 1 commit into
masterfrom
fix-species-params-list-column-diff

Conversation

@gustavdelius

Copy link
Copy Markdown
Member

Problem

The old-vs-new diff introduced in species_params<-() (mizer 3.2) compares every common column with:

changed <- !((old_vals == new_vals) | (is.na(old_vals) & is.na(new_vals)))

== is only reliable for plain atomic vectors:

  • List columns (and columns holding S4/other objects) error with "comparison of these types is not implemented", so species_params(params) <- sp fails outright.
  • Matrix columns return a matrix from == rather than one logical per species, so the changed mask and the downstream given[[col]][changed] <- ... indexing are wrong.

This means a model that carries a list column in species_params cannot round-trip through the setter at all. It surfaced in the downstream package mizerEcopath, whose ecopath_groups is a list column: every species_params(p) <- ... (including inside its Shiny tuning gadget) errored.

Fix

Take the fast == path only for plain atomic vectors (is.atomic, no dim, length no_sp), and otherwise compare per species with identical() — using row indexing for matrix columns and [[i]] for list columns. A newly-added given list column is initialised as a list rather than a scalar NA.

Behaviour for ordinary atomic columns is unchanged.

Tests

Added a regression test (species_params setter handles list and matrix columns) covering an unchanged round-trip, a detected change to a list element (recorded in given_species_params), and a matrix column round-trip. Full test-species_params.R passes (99 tests).

🤖 Generated with Claude Code

The old-vs-new diff in `species_params<-()` compared every common column
with `old_vals == new_vals`. This errors with "comparison of these types
is not implemented" for a list column (or a column holding S4/other
objects), and for a matrix column `==` returns a matrix rather than one
logical per species, so the change mask and the downstream indexing are
wrong.

Take the fast `==` path only for plain atomic vectors and fall back to a
per-species `identical()` comparison otherwise, and initialise a new
`given` list column as a list rather than a scalar `NA`.

Downstream packages that store a list column in `species_params` (e.g.
mizerEcopath's `ecopath_groups`) could not round-trip through
`species_params<-()` at all.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gustavdelius
gustavdelius merged commit 4b1c817 into master Jul 21, 2026
@gustavdelius
gustavdelius deleted the fix-species-params-list-column-diff branch July 21, 2026 06:33
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.

1 participant