Skip to content

[feat]: interactive model selection - #508

Open
JZahner1 wants to merge 21 commits into
nmfs-ost:mainfrom
JZahner1:feat-interactive-model-selection2
Open

JZahner1 wants to merge 21 commits into
nmfs-ost:mainfrom
JZahner1:feat-interactive-model-selection2

Conversation

@JZahner1

@JZahner1 JZahner1 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What is the feature?

  • Allow for interactive selection of model when multiple models are present in the data. This is akin to the interactive selection feature available for selecting from multiple modules when plotting.

How have you implemented the solution?

  • The original interactive module selection code was generalized to work for multiple columns (though is only currently implemented and tested for module_name and model). A module parameter was added to all plot_* and table_* functions to facilitate allowing users to filter by model directly from the function call. For plot_* functions, multiple models may be selected (an "All" option is also available to allow for quick plotting of all available models), but only one model may be selected for table_* functions.

Does the PR impact any other area of the project, maybe another repo?

PR contribution checklist

Thank you for contributing to stockplotr! Please check the boxes below to confirm this pull request (PR) is ready for review. Edit this PR description to add the release indicator and any explanations.

  • I have read and adhered to the contributor guide.
  • I have kept this PR focused on one plot where applicable. For multiple features, I have used separate PRs (stacked PRs are welcome if needed).
  • I have aimed to keep this PR to no more than 750 lines, excluding tests and example data (for example, up to 750 lines for a new function).
  • If I have provided an example dataset, I have explained why the existing sample datasets are not sufficient.
  • I have tested that my changes are compatible with all example outputs in the "data" folder (example_data.rda; pollock.rda; ss3_simple.rda; vermilion_snapper.rda).
  • If I didn't follow the development workflow, I have explained why in this PR.
  • If applicable, I've added the plot to save_all_plots() and updated the associated tests in test-save_all_plots.R.
  • After opening this PR, I have checked that my own tests and spellcheck pass (spelling::spell_check_package()). If other checks fail, I have flagged them for the package maintainers to help diagnose and remedy.
  • I have requested review from one package maintainer (Sam or Sophie).

@JZahner1 JZahner1 added the enhancement New feature or request label Nov 17, 2026
@JZahner1

Copy link
Copy Markdown
Collaborator Author

@Schiano-NOAA this is the code for what we were talking about yesterday. Its not explicitly necessary for the multi-model features that were previously merged, but this ensures that tables don't get wonky when multiple models are present in the data.

Comment thread R/utils_plot.R Resolved
Comment thread R/plot_spawning_biomass.R Resolved

@sbreitbart-NOAA sbreitbart-NOAA left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for developing this feature- I think it'll be very useful down the road! I've added some questions and suggestions and wanted to share them before I start testing the code later today/tomorrow.

Comment thread R/plot_spawning_biomass.R Resolved
Comment thread R/plot_spawning_biomass.R Resolved
Comment thread R/table_biomass_abundance_catch.R Resolved
Comment thread R/table_landings.R Resolved
Comment thread R/table_projections.R Resolved
Comment thread R/utils_plot.R Resolved
Changed `kws` to `pretty_columns`
Comment thread R/plot_abundance_at_age.R Resolved
Comment thread R/utils_plot.R Resolved

@sbreitbart-NOAA sbreitbart-NOAA left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for addressing my comments. I think this looks really good now. One last note is that some plots are still leaving "selected_model" as an object in the R environment- that obj should be removed at the very end (example: plot_biomass()). I'm going to start a review from copilot but assuming that goes fine, I'll merge this in!

EDIT: Copilot raised several imporant points. Please address those (or at least respond with why they're irrelevant).

During testing, I noticed that several of my own examples gave various errors; however, I don't think those failures apply to this PR so I'll make an issue if they persist.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Selecting multiple models can crash, while several plots and tables inconsistently apply model selections, producing incorrect data, reference lines, or captions.

9 open issues
9 files not reviewed
  • man/conout_bam.Rd: Generated file
  • man/conout_rceattle.Rd: Generated file
  • man/conout_ss3.Rd: Generated file
  • man/convert_output.Rd: Generated file
  • man/filter_data.Rd: Generated file
  • man/filter_interactive.Rd: Generated file
  • man/plot_abundance_at_age.Rd: Generated file
  • man/plot_biomass.Rd: Generated file
  • man/plot_biomass_at_age.Rd: Generated file
What changed in this PR

This PR extends stockplotr’s existing interactive module selection to models, allowing users to choose assessments from combined datasets when creating plots and tables.

Changes:

  • Generalize selection logic for models and modules, including an “All” model option.
  • Add model parameters across plotting and table functions and reuse selections in composite tables.
  • Update API documentation and existing multi-model tests.
File Description
tests/​testthat/​test-utils_plot.R Select both models explicitly in filtering tests.
tests/​testthat/​test-plot_spawning_biomass.R Specify models in the multi-model plot test.
tests/​testthat/​test-plot_abundance_at_age.R Specify models in the multi-model plot test.
R/​utils_plot.R Add shared interactive selection and model filtering.
R/​table_total_catch.R Add model argument and single-model selection settings.
R/​table_projections.R Reuse model selection and adjust rounding and deduplication.
R/​table_landings.R Add model argument and single-model selection settings.
R/​table_index.R Expose model selection and clean up selection state.
R/​table_biomass_abundance_catch.R Reuse one model selection across quantities.
R/​plot_stock_recruitment.R Forward model selection to data filtering.
R/​plot_spr.R Forward model selection to data filtering.
R/​plot_spawning_biomass.R Add model selection and filter reference-layer input.
R/​plot_selectivity.R Forward model selection to data filtering.
R/​plot_recruitment.R Forward model selection to data filtering.
R/​plot_recruitment_deviations.R Forward model selection to data filtering.
R/​plot_natural_mortality.R Forward model selection to data filtering.
R/​plot_landings.R Add model selection and remove interval preprocessing.
R/​plot_index.R Forward model selection to data filtering.
R/​plot_fishing_mortality.R Forward model selection to data filtering.
R/​plot_discard.R Forward model selection to data filtering.
R/​plot_catch_at_age.R Forward model selection to data filtering.
R/​plot_biomass.R Forward model selection to data filtering.
R/​plot_biomass_at_age.R Forward model selection to data filtering.
R/​plot_abundance_at_age.R Document and forward model selection.
man/​table_total_catch.Rd Document the model parameter.
man/​table_projections.Rd Document the model parameter.
man/​table_landings.Rd Document the model parameter.
man/​table_index.Rd Document the model parameter.
man/​table_biomass_abundance_catch.Rd Document the model parameter.
man/​plot_stock_recruitment.Rd Document the model parameter.
man/​plot_spr.Rd Document the model parameter.
man/​plot_spawning_biomass.Rd Document the model parameter.
man/​plot_selectivity.Rd Document the model parameter.
man/​plot_recruitment.Rd Document the model parameter.
man/​plot_recruitment_deviations.Rd Document the model parameter.
man/​plot_natural_mortality.Rd Document the model parameter.
man/​plot_landings.Rd Document the model parameter.
man/​plot_index.Rd Document the model parameter.
man/​plot_fishing_mortality.Rd Document the model parameter.
man/​plot_discard.Rd Document the model parameter.
man/​plot_catch_at_age.Rd Document the model parameter.
man/​plot_biomass.Rd Document the model parameter.
man/​plot_biomass_at_age.Rd Document the model parameter.
man/​plot_abundance_at_age.Rd Document the model parameter.
man/​filter_interactive.Rd Add documentation for the shared selection helper.
man/​filter_data.Rd Document model filtering and selection cardinality.
man/​convert_output.Rd Refresh usage and converter argument descriptions.
man/​conout_ss3.Rd Refresh converter argument documentation.
man/​conout_rceattle.Rd Refresh converter argument documentation.
man/​conout_bam.Rd Refresh converter argument documentation.

Review effort: Balanced

Comment thread R/utils_plot.R Resolved
Comment thread R/plot_biomass.R Resolved
Comment thread R/plot_biomass.R Resolved
Comment thread R/plot_landings.R
group = group,
facet = facet,
module = module,
model = model,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems worth looking into, though may be moot or different after rebasing with the main branch, which has Eric's PR merged in now

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Im not sure I really understand this comment...

Comment thread R/plot_landings.R Resolved
Comment thread R/plot_spawning_biomass.R Resolved
Comment thread R/table_index.R Resolved
Comment thread R/table_total_catch.R Resolved
Comment thread R/utils_plot.R Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants