Skip to content

Keep the given_species_params class in record_given_species_params() - #472

Open
gustavdelius wants to merge 1 commit into
masterfrom
record-given-preserve-class
Open

Keep the given_species_params class in record_given_species_params()#472
gustavdelius wants to merge 1 commit into
masterfrom
record-given-preserve-class

Conversation

@gustavdelius

Copy link
Copy Markdown
Member

Follow-up to #471.

record_given_species_params() added wholly new columns with cbind(), which returns a plain data frame and so stripped the given_species_params/species_params class from the result. Without the class, $.species_params no longer applies, and

given_species_params(params)$w_mat

comes back without the species names that species_params(params)$w_mat carries — an inconsistency between the two accessors that should not exist.

species_params<-() never showed this, because the setParams() call at the end of the method restores the class. The bug only became reachable when the recording step was exported for standalone use, and it showed up immediately in mizerEcopath: after setFeedingLevels() recorded its new h and ks, given_species_params(params)$h was unnamed while species_params(params)$h was named.

The fix assigns the new columns one at a time, which preserves both the class and the row names.

Regression test covers the class, the row names and the naming done by $, with and without a new column. Full suite: 3370 pass, 0 fail.

🤖 Generated with Claude Code

New columns were added with `cbind()`, which returns a plain data frame
and so stripped the `given_species_params`/`species_params` class from
the result. Without the class, `$.species_params` no longer applies and
`given_species_params(params)$w_mat` comes back without the species
names that `species_params(params)$w_mat` carries.

`species_params<-()` did not show this because the `setParams()` call at
the end of the method restores the class. The bug only became reachable
when the recording step was exported for standalone use.

Assign the new columns one at a time instead, which preserves the class
and the row names.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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