Fix species_params<-() diff for list, matrix and object columns#465
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The old-vs-new diff introduced in
species_params<-()(mizer 3.2) compares every common column with:==is only reliable for plain atomic vectors:species_params(params) <- spfails outright.==rather than one logical per species, so thechangedmask and the downstreamgiven[[col]][changed] <- ...indexing are wrong.This means a model that carries a list column in
species_paramscannot round-trip through the setter at all. It surfaced in the downstream package mizerEcopath, whoseecopath_groupsis a list column: everyspecies_params(p) <- ...(including inside its Shiny tuning gadget) errored.Fix
Take the fast
==path only for plain atomic vectors (is.atomic, nodim, lengthno_sp), and otherwise compare per species withidentical()— using row indexing for matrix columns and[[i]]for list columns. A newly-addedgivenlist column is initialised as a list rather than a scalarNA.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 ingiven_species_params), and a matrix column round-trip. Fulltest-species_params.Rpasses (99 tests).🤖 Generated with Claude Code