From 763ec0abd4cd0cc3b174e30171c700773d0437c0 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 16 Nov 2026 19:07:22 -0500 Subject: [PATCH 01/19] refactor: pull interactive selection code into function for reuse across possible columns og code for interactive filtering of module_name, now extended to also work for model column --- R/utils_plot.R | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/R/utils_plot.R b/R/utils_plot.R index cfb47702..51fcbde8 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -1231,3 +1231,101 @@ add_reference_line <- function( } # close if ref_line NULL ref_lines_list } + + +#' Filter plot data interactively +#' +#' Allows user to interactively select values from those available +#' to filter their data by. +#' +#' @param dat data.frame. A tibble or named list of tibbles (input as `list()`) +#' returned from \link[stockplotr]{convert_output}. +#' +#' @param column_name String. Name of the column to allow interactive filtering for. +#' +#' @param column_value String. Value of the column to filter by. If NULL, interactive +#' selection will be enabled. +#' +#' Default: NULL +#' +#' @param interactive Logical. indicate whether the environment is interactive. +#' +#' Default: TRUE +#' +#' @param allow_multiple_models Logical. Whether to allow the selection of multiple +#' models. +#' +#' Default: FALSE +#' +#' @return List. filtered data.frame (`plot_data`) and selected option(`selected)` +filter_interactive <- function( + dat, + column_name, + column_value = NULL, + interactive = TRUE, + allow_multiple_selection = TRUE +){ + + kws <- c("module_name"="module", "model"="model") + + plot_dat <- dat + selected <- unique(dat[[column_name]]) + if(length(unique(dat[[column_name]])) > 1){ + available_names <- unique(dat[[column_name]]) + if(!is.null(column_value)){ + if(length(column_value) > 1 && !allow_multiple_selection){ + cli::cli_alert_danger("Multiple {kws[column_name]}s provided, but only 1 allowed. Defaulting to first available {kws[column_name]} name: {available_names[1]}.") + } + plot_dat <- dat |> dplyr::filter(.data[[column_name]] %in% column_value) + selected <- column_value + }else{ + cli::cli_alert_warning("Multiple {kws[column_name]}s found in data. \n") + options <- c() + for (i in seq_along(available_names)) { + # options <- paste0(options, " ", i, ") ", unique(plot_data$module_name)[i], "\n") + options[i] <- paste0(available_names[i]) + } + + if(column_name == "model"){ + options <- c(options, "All") + } + + if(interactive()){ + if(interactive){ + selection <- utils::select.list( + options, + multiple=allow_multiple_selection, + title = glue::glue("Select one of the following {kws[column_name]} names") + ) + question1 <- if(length(selection)==0 || identical(selection, "")){ + options[1] + }else if(selection=="All"){ + options[-length(options)] + }else{ + selection + } + + selected <- intersect(available_names, question1) + if (length(selected) < 1 || (length(selected) > 1 && !allow_multiple_selection)) { + selected <- available_names[1] + } + }else{ + selected <- available_names[1] + cli::cli_alert_info("Selection bypassed. Filtering by {selected}.") + } + }else{ + selected <- available_names[1] + cli::cli_alert_info(glue::glue("Environment not interactive. Selecting {selected}.")) + } + if (length(selected) > 0) { + plot_dat <- dat |> + dplyr::filter( + .data[[column_name]] %in% selected + ) + } + } + } + out <- list("plot_data"=plot_dat, "selected"=selected) + + return(out) +} From 53c4f79f9b843e6f95138fd66055dd8ac403eeb0 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 16 Nov 2026 19:08:19 -0500 Subject: [PATCH 02/19] refactor: use filter_interactive for module_name selection --- R/utils_plot.R | 61 +++++++++----------------------------------------- 1 file changed, 10 insertions(+), 51 deletions(-) diff --git a/R/utils_plot.R b/R/utils_plot.R index 51fcbde8..04469af4 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -775,57 +775,16 @@ filter_data <- function( } # Check if there are multiple module_names present - if (length(unique(plot_data$module_name)) > 1) { - module_names <- unique(plot_data$module_name) - if (!is.null(module)) { - plot_data <- plot_data |> - dplyr::filter( - module_name %in% module - ) - # export module to environment for use with key quantity calc - selected_module <<- module - } else { - cli::cli_alert_warning("Multiple module names found in data. \n") - options <- c() - for (i in seq_along(module_names)) { - # options <- paste0(options, " ", i, ") ", unique(plot_data$module_name)[i], "\n") - options[i] <- paste0(module_names[i]) - } - if (interactive()) { - if (interactive) { - selected <- utils::select.list( - options, - multiple = TRUE, - title = "Select one or more of the following module names" - ) - question1 <- if (length(selected) == 0 || identical(selected, "")) { - options[1] - } else { - selected - } - # use <<- to export module to environment for use with key quantity calc - selected_module <<- intersect(module_names, question1) - if (length(selected_module) < 1) { - selected_module <<- module_names[1] - } - } else { - # use <<- to export module to environment for use with key quantity calc - selected_module <<- module_names[1] - cli::cli_alert_info("Selection bypassed. Filtering by {selected_module}.") - } - } else { - # use <<- to export module to environment for use with key quantity calc - selected_module <<- module_names[1] - cli::cli_alert_info(glue::glue("Environment not interactive. Selecting {selected_module}.")) - } - if (length(selected_module) > 0) { - plot_data <- plot_data |> - dplyr::filter( - module_name %in% selected_module - ) - } - } - } + module_select <- filter_interactive( + plot_data, + column_name="module_name", + column_value=module, + interactive=interactive, + allow_multiple_selection = TRUE + ) + plot_data <- module_select$plot_data + selected_module <<- module_select$selected + # TODO: add lines to summarize final data for selected grouping and or facet if (geom == "area") { plot_data <- dplyr::mutate( From a333b9279531d0f25415b7ec1961552616d4d727 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 16 Nov 2026 19:10:33 -0500 Subject: [PATCH 03/19] feat: allow for interactive selection of model users may interactively choose model(s) to plot from the terminal, akin to module selection --- R/utils_plot.R | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/R/utils_plot.R b/R/utils_plot.R index 04469af4..0c5c5c14 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -675,6 +675,9 @@ cap_first_letter <- function(s) { #' @inheritParams plot_spawning_biomass #' @param label_name String. Name of the label used to filter #' the data. +#' @param allow_multiple_models Logical. Whetehr to allow multiple models. +#' +#' Default: TRUE #' #' @returns a data frame that is preformatted for plotting with ggplot2. #' @export @@ -687,13 +690,27 @@ filter_data <- function( dat, label_name, module = NULL, + model = NULL, era = NULL, geom, group = NULL, facet = NULL, scale_amount = 1, - interactive = TRUE + interactive = TRUE, + allow_multiple_models = TRUE ) { + + # Check if there are multiple module_names present + model_select <- filter_interactive( + dat, + column_name="model", + column_value=model, + interactive=interactive, + allow_multiple_selection = allow_multiple_models + ) + dat <- model_select$plot_data + selected_model <<- model_select$selected + # TODO: add method to filter by units once added into the converter # TODO: add option to scale data # Replace all spaces with underscore if not in proper format From d14d1049c5ddcb13783a7a5f54a5f98168847946 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 16 Nov 2026 19:11:48 -0500 Subject: [PATCH 04/19] feat: allow for interactive model selection for all plotting functions --- R/plot_abundance_at_age.R | 5 ++++- R/plot_biomass.R | 5 ++++- R/plot_biomass_at_age.R | 5 ++++- R/plot_catch_at_age.R | 5 ++++- R/plot_discard.R | 5 ++++- R/plot_fishing_mortality.R | 5 ++++- R/plot_index.R | 5 ++++- R/plot_landings.R | 5 ++++- R/plot_natural_mortality.R | 5 ++++- R/plot_recruitment.R | 5 ++++- R/plot_recruitment_deviations.R | 5 ++++- R/plot_selectivity.R | 5 ++++- R/plot_spawning_biomass.R | 7 +++++-- R/plot_spr.R | 5 ++++- R/plot_stock_recruitment.R | 5 ++++- 15 files changed, 61 insertions(+), 16 deletions(-) diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index 480da3a1..c7977171 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -81,6 +81,7 @@ plot_abundance_at_age <- function( scale_amount = 1, proportional = TRUE, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -94,8 +95,10 @@ plot_abundance_at_age <- function( geom = "point", group = "age", module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # Create label for abundance units in legend diff --git a/R/plot_biomass.R b/R/plot_biomass.R index 211056d0..1e144498 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -50,6 +50,7 @@ plot_biomass <- function( era = NULL, unit_label = NULL, module = NULL, + model = NULL, scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -84,8 +85,10 @@ plot_biomass <- function( facet = facet, era = era, module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) if (is.null(unit_label)) { diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index f335ed19..362db96c 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -46,6 +46,7 @@ plot_biomass_at_age <- function( scale_amount = 1, proportional = TRUE, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -61,8 +62,10 @@ plot_biomass_at_age <- function( group = "age", era = "time", module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) if (is.null(unit_label)) { diff --git a/R/plot_catch_at_age.R b/R/plot_catch_at_age.R index 78308e52..c3922351 100644 --- a/R/plot_catch_at_age.R +++ b/R/plot_catch_at_age.R @@ -74,6 +74,7 @@ plot_catch_at_age <- function( proportional = TRUE, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) { @@ -89,7 +90,9 @@ plot_catch_at_age <- function( group = "age", scale_amount = scale_amount, interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) if (is.null(unit_label)) { unit_label <- unique(catch$unit) diff --git a/R/plot_discard.R b/R/plot_discard.R index a547c266..b7b8b036 100644 --- a/R/plot_discard.R +++ b/R/plot_discard.R @@ -35,6 +35,7 @@ plot_discard <- function( scale_amount = 1, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) { @@ -55,8 +56,10 @@ plot_discard <- function( group = group, facet = facet, module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # extract unit if unit_label is null and set lbs to F by default diff --git a/R/plot_fishing_mortality.R b/R/plot_fishing_mortality.R index ccbb73d7..0bfcb9dc 100644 --- a/R/plot_fishing_mortality.R +++ b/R/plot_fishing_mortality.R @@ -36,6 +36,7 @@ plot_fishing_mortality <- function( ref_line = "msy", era = NULL, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), interactive = TRUE, @@ -54,8 +55,10 @@ plot_fishing_mortality <- function( group = group, facet = facet, module = module, + model = model, scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # Process data processed_data <- process_data( diff --git a/R/plot_index.R b/R/plot_index.R index e788f93b..6ded85b9 100644 --- a/R/plot_index.R +++ b/R/plot_index.R @@ -84,6 +84,7 @@ plot_index <- function( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, focus = NULL, interval = 0.95, log = FALSE, @@ -119,7 +120,9 @@ plot_index <- function( group = group, facet = facet, interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) # There's 3 cases handled here diff --git a/R/plot_landings.R b/R/plot_landings.R index 61493ae2..a66b23c9 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -44,6 +44,7 @@ plot_landings <- function( era = NULL, scale_amount = 1, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), @@ -60,8 +61,10 @@ plot_landings <- function( group = group, facet = facet, module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # |> # filter NA from year # dplyr::filter(!is.na(year)) diff --git a/R/plot_natural_mortality.R b/R/plot_natural_mortality.R index 09d1c1e9..e53c3882 100644 --- a/R/plot_natural_mortality.R +++ b/R/plot_natural_mortality.R @@ -26,6 +26,7 @@ plot_natural_mortality <- function( era = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), ... @@ -43,7 +44,9 @@ plot_natural_mortality <- function( facet = facet, geom = "line", interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) # Set group back to NULL if it is age since this is an at age plot diff --git a/R/plot_recruitment.R b/R/plot_recruitment.R index 5dbf3c9a..d6190d2a 100644 --- a/R/plot_recruitment.R +++ b/R/plot_recruitment.R @@ -42,6 +42,7 @@ plot_recruitment <- function( # relative = FALSE, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) { @@ -57,7 +58,9 @@ plot_recruitment <- function( facet = facet, interactive = interactive, module = module, - scale_amount = scale_amount + model = model, + scale_amount = scale_amount, + allow_multiple_models = TRUE ) # process data processed_data <- process_data( diff --git a/R/plot_recruitment_deviations.R b/R/plot_recruitment_deviations.R index f2ad753d..638cc5c9 100644 --- a/R/plot_recruitment_deviations.R +++ b/R/plot_recruitment_deviations.R @@ -33,6 +33,7 @@ plot_recruitment_deviations <- function( dat, module = NULL, + model = NULL, era = NULL, interactive = TRUE, make_rda = FALSE, @@ -46,10 +47,12 @@ plot_recruitment_deviations <- function( dat = dat, label_name = "recruitment_deviations", module = module, + model = model, era = era, interactive = interactive, geom = "point", - group = NULL + group = NULL, + allow_multiple_models = TRUE ) # Process data processed_data <- process_data( diff --git a/R/plot_selectivity.R b/R/plot_selectivity.R index d4781ad4..4d34336c 100644 --- a/R/plot_selectivity.R +++ b/R/plot_selectivity.R @@ -37,6 +37,7 @@ plot_selectivity <- function( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), ... @@ -52,7 +53,9 @@ plot_selectivity <- function( group = group, facet = facet, interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) if (is.null(unit_label)) { diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index 1047b598..0f647333 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -132,6 +132,7 @@ plot_spawning_biomass <- function( era = NULL, lbs = lifecycle::deprecated(), module = NULL, + model = NULL, scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -155,6 +156,7 @@ plot_spawning_biomass <- function( group = group, facet = facet, module = module, + model = model, scale_amount = scale_amount, interactive = interactive ) @@ -212,7 +214,7 @@ plot_spawning_biomass <- function( group = group, # add check in case facet is returned as character(0) facet = if (length(facet) > 0) facet else NULL, - ... + # ... ) # Add reference line if (relative) { @@ -221,7 +223,7 @@ plot_spawning_biomass <- function( } else { final <- plt + add_reference_line( - dat = dat, + dat = dat |> dplyr::filter(model %in% selected_model), ref_line = ref_line, label = "spawning_biomass", lbs = lbs, @@ -308,6 +310,7 @@ plot_spawning_biomass <- function( if (exists("selected_module")) { rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) } # Output final plot diff --git a/R/plot_spr.R b/R/plot_spr.R index dc000ab2..b1d91a83 100644 --- a/R/plot_spr.R +++ b/R/plot_spr.R @@ -41,6 +41,7 @@ plot_spr <- function( ref_line = "target", era = "time", module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), @@ -59,8 +60,10 @@ plot_spr <- function( group = group, facet = facet, module = module, + model = model, scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) |> # filter NA from year dplyr::filter(!is.na(year)) diff --git a/R/plot_stock_recruitment.R b/R/plot_stock_recruitment.R index e0debed2..dbdf270f 100644 --- a/R/plot_stock_recruitment.R +++ b/R/plot_stock_recruitment.R @@ -43,6 +43,7 @@ plot_stock_recruitment <- function( interactive = TRUE, era = NULL, module = NULL, + model = NULL, scale_amount = 1, make_rda = FALSE, figures_dir = getwd() @@ -58,7 +59,9 @@ plot_stock_recruitment <- function( geom = "point", scale_amount = scale_amount, interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) |> # filter for year !na dplyr::filter( From fefe960a9c673ff22a4cc76402bf6290ff77c254 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 16 Nov 2026 19:13:50 -0500 Subject: [PATCH 05/19] fix: fix error where projection tables only showing data from first forecast year was occurring bc of use of ifelse which only returns the first value of a vector --- R/table_projections.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/table_projections.R b/R/table_projections.R index b18c429a..82daf272 100644 --- a/R/table_projections.R +++ b/R/table_projections.R @@ -73,8 +73,16 @@ table_projections <- function( scale_amount = 1, interactive = interactive ) |> - dplyr::mutate(estimate = ifelse(x != "fishing_mortality", round(as.numeric(estimate), digits = 0), round(as.numeric(estimate), digits = 4))) |> - dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = 2)) + dplyr::mutate( + estimate = if(x != "fishing_mortality"){ + round(as.numeric(estimate), digits=0) + }else{ + round(as.numeric(estimate), digits = 4) + } + ) |> + # estimate = ifelse(x != "fishing_mortality", round(as.numeric(estimate), digits = 0), round(as.numeric(estimate), digits = 4))) |> + dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = 2)) |> + dplyr::distinct() # only preserve unique rows uncertainty_label <- ifelse( is.na(unique(filtered_data$uncertainty_label)), "Uncertainty", From 523f4bfad6ab5259595ab05c770b84c3a62c27a7 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 16 Nov 2026 19:14:24 -0500 Subject: [PATCH 06/19] feat: allow for interactive model selection for all table functions --- R/table_biomass_abundance_catch.R | 12 +++++++++++- R/table_index.R | 9 ++++++++- R/table_landings.R | 8 +++++++- R/table_projections.R | 13 ++++++++++++- R/table_total_catch.R | 6 +++++- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/R/table_biomass_abundance_catch.R b/R/table_biomass_abundance_catch.R index a29ddfa3..417ff754 100644 --- a/R/table_biomass_abundance_catch.R +++ b/R/table_biomass_abundance_catch.R @@ -67,6 +67,7 @@ table_biomass_abundance_catch <- function( method = "sum", module = NULL, label = NULL, + model = NULL, make_rda = FALSE, tables_dir = getwd() ) { @@ -82,6 +83,9 @@ table_biomass_abundance_catch <- function( biomass_abundance_catch.abundance.units <- NA biomass_abundance_catch.catch.units <- NA + # Do this so that we don't have to repeatedly choose the same model + selected_model <- model + # Aiming for totals # iterate through label_names lab_list <- purrr::map( @@ -95,9 +99,12 @@ table_biomass_abundance_catch <- function( geom = "line", era = "time", module = module, + model = selected_model[1], scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) + selected_model <<- unique(filtered_data$model) uncertainty_label <- ifelse( is.na(unique(filtered_data$uncertainty_label)), @@ -235,7 +242,10 @@ table_biomass_abundance_catch <- function( if (exists("selected_module")) { rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) } final } + +# table_biomass_abundance_catch(result) diff --git a/R/table_index.R b/R/table_index.R index 9e41058c..05e356a4 100644 --- a/R/table_index.R +++ b/R/table_index.R @@ -54,6 +54,7 @@ table_index <- function( group = NULL, method = "sum", module = NULL, + model = NULL, label = NULL, digits = 2, make_rda = FALSE, @@ -69,6 +70,7 @@ table_index <- function( geom = "line", era = era, module = module, + model = model, scale_amount = 1, interactive = interactive ) |> @@ -162,5 +164,10 @@ table_index <- function( ) } + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) + } + final -} +} \ No newline at end of file diff --git a/R/table_landings.R b/R/table_landings.R index 98ecf2fc..fe175b20 100644 --- a/R/table_landings.R +++ b/R/table_landings.R @@ -62,6 +62,7 @@ table_landings <- function( group = NULL, method = "sum", module = NULL, + model = NULL, label = NULL, digits = 2, scale_amount = 1, @@ -81,8 +82,10 @@ table_landings <- function( geom = "line", era = era, module = module, + model = NULL, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) |> dplyr::mutate(estimate = round(as.numeric(estimate), digits = digits)) |> dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = digits)) @@ -192,3 +195,6 @@ table_landings <- function( final } + +# table_landings(result) + diff --git a/R/table_projections.R b/R/table_projections.R index 82daf272..44ddbcba 100644 --- a/R/table_projections.R +++ b/R/table_projections.R @@ -37,6 +37,7 @@ table_projections <- function( spawning_biomass_label = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, tables_dir = getwd() ) { @@ -59,6 +60,8 @@ table_projections <- function( "fishing_mortality" = "fishing_mortality" ) + selected_model <- model + # iterate through 3 label names lab_list <- purrr::map( names(named_vec), @@ -70,8 +73,10 @@ table_projections <- function( geom = "line", era = "fore", module = module, + model = selected_model, scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) |> dplyr::mutate( estimate = if(x != "fishing_mortality"){ @@ -83,6 +88,9 @@ table_projections <- function( # estimate = ifelse(x != "fishing_mortality", round(as.numeric(estimate), digits = 0), round(as.numeric(estimate), digits = 4))) |> dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = 2)) |> dplyr::distinct() # only preserve unique rows + + selected_model <<- unique(filtered_data$model) + uncertainty_label <- ifelse( is.na(unique(filtered_data$uncertainty_label)), "Uncertainty", @@ -178,7 +186,10 @@ table_projections <- function( if (exists("selected_module")) { rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) } final } + +# table_projections(result) diff --git a/R/table_total_catch.R b/R/table_total_catch.R index 7965aa7a..ae36535e 100644 --- a/R/table_total_catch.R +++ b/R/table_total_catch.R @@ -44,6 +44,7 @@ table_total_catch <- function( era = NULL, interactive = TRUE, module = NULL, + model = NULL, scale_amount = 1, digits = 2, make_rda = FALSE, @@ -63,8 +64,10 @@ table_total_catch <- function( geom = "line", era = era, module = module, + model = NULL, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) # Check if there is any data and if all labels contain "catchability", not "catch" @@ -201,6 +204,7 @@ table_total_catch <- function( if (exists("selected_module")) { rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) } final From e63b3f2f3ed4d971d13f3b68b7b4824c4e393f4b Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 16 Nov 2026 19:14:52 -0500 Subject: [PATCH 07/19] tests: add tests for interactive model selection --- tests/testthat/test-plot_abundance_at_age.R | 2 +- tests/testthat/test-plot_spawning_biomass.R | 2 +- tests/testthat/test-utils_plot.R | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-plot_abundance_at_age.R b/tests/testthat/test-plot_abundance_at_age.R index 853f6563..140e23ae 100644 --- a/tests/testthat/test-plot_abundance_at_age.R +++ b/tests/testthat/test-plot_abundance_at_age.R @@ -171,7 +171,7 @@ test_that("plot_abundace_at_age generates plots for multiple models", { "model2" = r4ss::SS_output(test_path("fixtures", "ss3_models", "models", "Hake_2019_semi-parametric_selex")) )) - expect_no_error(plt <- plot_abundance_at_age(dat, module="natage")) + expect_no_error(plt <- plot_abundance_at_age(dat, module="natage", model=c("model1", "model2"))) expect_s3_class(plt, "gg") p <- ggplot2::ggplot_build(plt) diff --git a/tests/testthat/test-plot_spawning_biomass.R b/tests/testthat/test-plot_spawning_biomass.R index f12c97c6..8f26e1c5 100644 --- a/tests/testthat/test-plot_spawning_biomass.R +++ b/tests/testthat/test-plot_spawning_biomass.R @@ -63,7 +63,7 @@ test_that("plot_spawning_biomass generates plots for multiple models", { "model2" = r4ss::SS_output(test_path("fixtures", "ss3_models", "models", "Empirical_Wtatage_Age_Selex")) )) - expect_no_error(plt <- plot_spawning_biomass(dat, module="derived_quants")) + expect_no_error(plt <- plot_spawning_biomass(dat, module="derived_quants", model=c("model1", "model2"))) expect_s3_class(plt, "gg") p <- ggplot2::ggplot_build(plt) diff --git a/tests/testthat/test-utils_plot.R b/tests/testthat/test-utils_plot.R index 5e633c51..6457ba2d 100644 --- a/tests/testthat/test-utils_plot.R +++ b/tests/testthat/test-utils_plot.R @@ -62,7 +62,8 @@ test_that("filter_data handles data frames", { dat = mm_dat, label_name = "biomass", geom = "point", - interactive = FALSE + interactive = FALSE, + model = c("model_one", "model_two") ) expect_setequal(unique(filtered_list$model), c("model_one", "model_two")) expect_setequal(unique(filtered_list$group_var), c("model_one", "model_two")) From 10ead1c87c632352afe42668477e115ad1adc45d Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Tue, 17 Nov 2026 09:41:25 -0500 Subject: [PATCH 08/19] dcocs: update roxygen with model parameter --- R/plot_spawning_biomass.R | 7 +++++ man/conout_bam.Rd | 10 ++----- man/conout_rceattle.Rd | 10 ++----- man/conout_ss3.Rd | 10 ++----- man/convert_output.Rd | 18 ++++++++---- man/filter_data.Rd | 8 +++++- man/filter_interactive.Rd | 41 ++++++++++++++++++++++++++++ man/plot_abundance_at_age.Rd | 1 + man/plot_biomass.Rd | 1 + man/plot_biomass_at_age.Rd | 1 + man/plot_catch_at_age.Rd | 1 + man/plot_discard.Rd | 1 + man/plot_fishing_mortality.Rd | 1 + man/plot_index.Rd | 1 + man/plot_landings.Rd | 1 + man/plot_natural_mortality.Rd | 1 + man/plot_recruitment.Rd | 1 + man/plot_recruitment_deviations.Rd | 1 + man/plot_selectivity.Rd | 1 + man/plot_spawning_biomass.Rd | 9 ++++++ man/plot_spr.Rd | 1 + man/plot_stock_recruitment.Rd | 1 + man/table_biomass_abundance_catch.Rd | 1 + man/table_index.Rd | 1 + man/table_landings.Rd | 1 + man/table_projections.Rd | 1 + man/table_total_catch.Rd | 1 + 27 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 man/filter_interactive.Rd diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index 0f647333..65c7d698 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -59,6 +59,13 @@ #' #' If the interactive and >1 module_name is found, user will select the #' module_name in the console. @seealso [filter_data()] +#' @param mdoel Character vector. (Optional) Model name found in `dat$model`. +#' If selecting >1 model, place them in a vector like c("model1", "model2"). +#' +#' Default: NULL +#' +#' If the interactive and >1 model is found, user will select the +#' model in the console. @seealso [filter_data()] #' @param scale_amount Number. A number to scale the y-axis values. If > 1, the #' magnitude of the scale amount will be added to the unit label #' (e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result diff --git a/man/conout_bam.Rd b/man/conout_bam.Rd index 6cb63143..3cdb9be6 100644 --- a/man/conout_bam.Rd +++ b/man/conout_bam.Rd @@ -7,23 +7,19 @@ conout_bam(file, out_new, fleet_names = NULL) } \arguments{ -\item{file}{Path. Assessment model output file path. Currently accepts SS3 -\code{r4ss::ss_output()} or Report.sso file (being deprecated), BAM .rda file, Rceattle model object, and FIMS output -(the tibble returned by \code{FIMS::get_estimates()}, a \code{FIMSFit} object, or an .rds file with either).} - \item{out_new}{The empty standard output data frame from \code{\link[=convert_output]{convert_output()}}, which sets the columns of the output.} -\item{fleet_names}{List of Character vectors. Names of fleets in the assessment model as +\item{fleet_names}{List of named character vectors. Names of fleets in the assessment model as shortened in the output file or names of fleets to replace the native fleet names in the output. For example, if fleet names in the model are 1, 2, 3 then fleet_names = c("fleet1" = 1, "fleet2" = 2, "fleet3" = 3). Default: NULL -Should match length of \code{files}.} +Should match length of \code{files} if >1 model.} -\item{Path.}{Assessment model output file path. Currently accepts SS3 +\item{file.}{Assessment model output file path. Currently accepts SS3 Report.sso file, BAM .rda file, Rceattle model object, and FIMS model object.} } \value{ diff --git a/man/conout_rceattle.Rd b/man/conout_rceattle.Rd index 9e9e3734..7702fba6 100644 --- a/man/conout_rceattle.Rd +++ b/man/conout_rceattle.Rd @@ -7,23 +7,19 @@ conout_rceattle(file, out_new, fleet_names = NULL) } \arguments{ -\item{file}{Path. Assessment model output file path. Currently accepts SS3 -\code{r4ss::ss_output()} or Report.sso file (being deprecated), BAM .rda file, Rceattle model object, and FIMS output -(the tibble returned by \code{FIMS::get_estimates()}, a \code{FIMSFit} object, or an .rds file with either).} - \item{out_new}{The empty standard output data frame from \code{\link[=convert_output]{convert_output()}}, which sets the columns of the output.} -\item{fleet_names}{List of Character vectors. Names of fleets in the assessment model as +\item{fleet_names}{List of named character vectors. Names of fleets in the assessment model as shortened in the output file or names of fleets to replace the native fleet names in the output. For example, if fleet names in the model are 1, 2, 3 then fleet_names = c("fleet1" = 1, "fleet2" = 2, "fleet3" = 3). Default: NULL -Should match length of \code{files}.} +Should match length of \code{files} if >1 model.} -\item{Path.}{Assessment model output file path. Currently accepts SS3 +\item{file.}{Assessment model output file path. Currently accepts SS3 Report.sso file, BAM .rda file, Rceattle model object, and FIMS model object.} } \value{ diff --git a/man/conout_ss3.Rd b/man/conout_ss3.Rd index 8fdd5c43..25a79239 100644 --- a/man/conout_ss3.Rd +++ b/man/conout_ss3.Rd @@ -7,23 +7,19 @@ conout_ss3(file, out_new, fleet_names = NULL) } \arguments{ -\item{file}{Path. Assessment model output file path. Currently accepts SS3 -\code{r4ss::ss_output()} or Report.sso file (being deprecated), BAM .rda file, Rceattle model object, and FIMS output -(the tibble returned by \code{FIMS::get_estimates()}, a \code{FIMSFit} object, or an .rds file with either).} - \item{out_new}{The empty standard output data frame from \code{\link[=convert_output]{convert_output()}}, which sets the columns of the output.} -\item{fleet_names}{List of Character vectors. Names of fleets in the assessment model as +\item{fleet_names}{List of named character vectors. Names of fleets in the assessment model as shortened in the output file or names of fleets to replace the native fleet names in the output. For example, if fleet names in the model are 1, 2, 3 then fleet_names = c("fleet1" = 1, "fleet2" = 2, "fleet3" = 3). Default: NULL -Should match length of \code{files}.} +Should match length of \code{files} if >1 model.} -\item{Path.}{Assessment model output file path. Currently accepts SS3 +\item{file.}{Assessment model output file path. Currently accepts SS3 Report.sso file, BAM .rda file, Rceattle model object, and FIMS model object.} } \value{ diff --git a/man/convert_output.Rd b/man/convert_output.Rd index 30d010e4..71f61f17 100644 --- a/man/convert_output.Rd +++ b/man/convert_output.Rd @@ -4,13 +4,19 @@ \alias{convert_output} \title{Convert Output} \usage{ -convert_output(files, models = NULL, fleet_names = NULL, save_dir = NULL) +convert_output( + files, + models = NULL, + fleet_names = NULL, + save_dir = NULL, + start_year = NULL +) } \arguments{ \item{files}{List of Paths. Assessment model output file paths. Currently accepts SS3 \code{r4ss::ss_output()} or Report.sso file (being deprecated), BAM .rda file, Rceattle model object, -and FIMS output (the tibble returned by \code{FIMS::get_estimates()}, a \code{FIMSFit} object, or an -.rds file with either). If multiple elements, all valid models will be read, converted, and +and FIMS output (the tibble returned by \code{FIMS::get_estimates()}, a \code{FIMSFit} object, or an .rds +file with either). If multiple elements, all valid models will be read, converted, and appended together. \code{names(files)} will be used as the name of the model in the output.} @@ -21,16 +27,16 @@ Default: NULL Options: "ss3", "bam", "fims", "rceattle" -Should match length of \code{files}.} +Should match length of \code{files} if >1 model.} -\item{fleet_names}{List of Character vectors. Names of fleets in the assessment model as +\item{fleet_names}{List of named character vectors. Names of fleets in the assessment model as shortened in the output file or names of fleets to replace the native fleet names in the output. For example, if fleet names in the model are 1, 2, 3 then fleet_names = c("fleet1" = 1, "fleet2" = 2, "fleet3" = 3). Default: NULL -Should match length of \code{files}.} +Should match length of \code{files} if >1 model.} \item{save_dir}{Path. Full file path to save the converted output file. If saved file name is not indicated, the file will be saved as "std_output.rda" diff --git a/man/filter_data.Rd b/man/filter_data.Rd index 4884d58e..9b60be31 100644 --- a/man/filter_data.Rd +++ b/man/filter_data.Rd @@ -8,12 +8,14 @@ filter_data( dat, label_name, module = NULL, + model = NULL, era = NULL, geom, group = NULL, facet = NULL, scale_amount = 1, - interactive = TRUE + interactive = TRUE, + allow_multiple_models = TRUE ) } \arguments{ @@ -67,6 +69,10 @@ Default: 1} \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: \code{FALSE}} + +\item{allow_multiple_models}{Logical. Whetehr to allow multiple models. + +Default: TRUE} } \value{ a data frame that is preformatted for plotting with ggplot2. diff --git a/man/filter_interactive.Rd b/man/filter_interactive.Rd new file mode 100644 index 00000000..d3be9285 --- /dev/null +++ b/man/filter_interactive.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_plot.R +\name{filter_interactive} +\alias{filter_interactive} +\title{Filter plot data interactively} +\usage{ +filter_interactive( + dat, + column_name, + column_value = NULL, + interactive = TRUE, + allow_multiple_selection = TRUE +) +} +\arguments{ +\item{dat}{data.frame. A tibble or named list of tibbles (input as \code{list()}) +returned from \link[stockplotr]{convert_output}.} + +\item{column_name}{String. Name of the column to allow interactive filtering for.} + +\item{column_value}{String. Value of the column to filter by. If NULL, interactive +selection will be enabled. + +Default: NULL} + +\item{interactive}{Logical. indicate whether the environment is interactive. + +Default: TRUE} + +\item{allow_multiple_models}{Logical. Whether to allow the selection of multiple +models. + +Default: FALSE} +} +\value{ +List. filtered data.frame (\code{plot_data}) and selected option(\verb{selected)} +} +\description{ +Allows user to interactively select values from those available +to filter their data by. +} diff --git a/man/plot_abundance_at_age.Rd b/man/plot_abundance_at_age.Rd index 3dd4ff31..67ab8443 100644 --- a/man/plot_abundance_at_age.Rd +++ b/man/plot_abundance_at_age.Rd @@ -11,6 +11,7 @@ plot_abundance_at_age( scale_amount = 1, proportional = TRUE, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() diff --git a/man/plot_biomass.Rd b/man/plot_biomass.Rd index e0881fa3..3a1c923e 100644 --- a/man/plot_biomass.Rd +++ b/man/plot_biomass.Rd @@ -13,6 +13,7 @@ plot_biomass( era = NULL, unit_label = NULL, module = NULL, + model = NULL, scale_amount = 1, relative = FALSE, make_rda = FALSE, diff --git a/man/plot_biomass_at_age.Rd b/man/plot_biomass_at_age.Rd index 66e19b6d..c30b4eba 100644 --- a/man/plot_biomass_at_age.Rd +++ b/man/plot_biomass_at_age.Rd @@ -11,6 +11,7 @@ plot_biomass_at_age( scale_amount = 1, proportional = TRUE, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() diff --git a/man/plot_catch_at_age.Rd b/man/plot_catch_at_age.Rd index 8044bc76..05130a44 100644 --- a/man/plot_catch_at_age.Rd +++ b/man/plot_catch_at_age.Rd @@ -13,6 +13,7 @@ plot_catch_at_age( proportional = TRUE, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) diff --git a/man/plot_discard.Rd b/man/plot_discard.Rd index 61f21df0..68912086 100644 --- a/man/plot_discard.Rd +++ b/man/plot_discard.Rd @@ -14,6 +14,7 @@ plot_discard( scale_amount = 1, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) diff --git a/man/plot_fishing_mortality.Rd b/man/plot_fishing_mortality.Rd index c0c449b1..fa8af9b0 100644 --- a/man/plot_fishing_mortality.Rd +++ b/man/plot_fishing_mortality.Rd @@ -12,6 +12,7 @@ plot_fishing_mortality( ref_line = "msy", era = NULL, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), interactive = TRUE, diff --git a/man/plot_index.Rd b/man/plot_index.Rd index 20003694..b7615cfe 100644 --- a/man/plot_index.Rd +++ b/man/plot_index.Rd @@ -11,6 +11,7 @@ plot_index( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, focus = NULL, interval = 0.95, log = FALSE, diff --git a/man/plot_landings.Rd b/man/plot_landings.Rd index 60543b67..b7e55694 100644 --- a/man/plot_landings.Rd +++ b/man/plot_landings.Rd @@ -14,6 +14,7 @@ plot_landings( era = NULL, scale_amount = 1, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), diff --git a/man/plot_natural_mortality.Rd b/man/plot_natural_mortality.Rd index 0e6bddf5..1d5584c4 100644 --- a/man/plot_natural_mortality.Rd +++ b/man/plot_natural_mortality.Rd @@ -11,6 +11,7 @@ plot_natural_mortality( era = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), ... diff --git a/man/plot_recruitment.Rd b/man/plot_recruitment.Rd index b7b5b170..d538ad43 100644 --- a/man/plot_recruitment.Rd +++ b/man/plot_recruitment.Rd @@ -13,6 +13,7 @@ plot_recruitment( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) diff --git a/man/plot_recruitment_deviations.Rd b/man/plot_recruitment_deviations.Rd index 80369856..ea3cbb24 100644 --- a/man/plot_recruitment_deviations.Rd +++ b/man/plot_recruitment_deviations.Rd @@ -7,6 +7,7 @@ plot_recruitment_deviations( dat, module = NULL, + model = NULL, era = NULL, interactive = TRUE, make_rda = FALSE, diff --git a/man/plot_selectivity.Rd b/man/plot_selectivity.Rd index 4a70ccba..bfab05a5 100644 --- a/man/plot_selectivity.Rd +++ b/man/plot_selectivity.Rd @@ -11,6 +11,7 @@ plot_selectivity( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), ... diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index ab616183..0fa2e28d 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -14,6 +14,7 @@ plot_spawning_biomass( era = NULL, lbs = lifecycle::deprecated(), module = NULL, + model = NULL, scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -118,6 +119,14 @@ The folder is created within the path if it does not exist.} Default: \code{FALSE}} \item{...}{Arguments called from \link[ggplot2]{geom_line} or \link[ggplot2]{geom_point}} + +\item{mdoel}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} } \value{ A plot showing spawning biomass over time. diff --git a/man/plot_spr.Rd b/man/plot_spr.Rd index a329fdfd..14a3e352 100644 --- a/man/plot_spr.Rd +++ b/man/plot_spr.Rd @@ -12,6 +12,7 @@ plot_spr( ref_line = "target", era = "time", module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), diff --git a/man/plot_stock_recruitment.Rd b/man/plot_stock_recruitment.Rd index c9d11886..742df437 100644 --- a/man/plot_stock_recruitment.Rd +++ b/man/plot_stock_recruitment.Rd @@ -11,6 +11,7 @@ plot_stock_recruitment( interactive = TRUE, era = NULL, module = NULL, + model = NULL, scale_amount = 1, make_rda = FALSE, figures_dir = getwd() diff --git a/man/table_biomass_abundance_catch.Rd b/man/table_biomass_abundance_catch.Rd index e289ff3f..a6471d8f 100644 --- a/man/table_biomass_abundance_catch.Rd +++ b/man/table_biomass_abundance_catch.Rd @@ -15,6 +15,7 @@ table_biomass_abundance_catch( method = "sum", module = NULL, label = NULL, + model = NULL, make_rda = FALSE, tables_dir = getwd() ) diff --git a/man/table_index.Rd b/man/table_index.Rd index 96a8327a..46369470 100644 --- a/man/table_index.Rd +++ b/man/table_index.Rd @@ -11,6 +11,7 @@ table_index( group = NULL, method = "sum", module = NULL, + model = NULL, label = NULL, digits = 2, make_rda = FALSE, diff --git a/man/table_landings.Rd b/man/table_landings.Rd index d0f1989a..b7bc038e 100644 --- a/man/table_landings.Rd +++ b/man/table_landings.Rd @@ -12,6 +12,7 @@ table_landings( group = NULL, method = "sum", module = NULL, + model = NULL, label = NULL, digits = 2, scale_amount = 1, diff --git a/man/table_projections.Rd b/man/table_projections.Rd index b3e3e049..68a9407c 100644 --- a/man/table_projections.Rd +++ b/man/table_projections.Rd @@ -10,6 +10,7 @@ table_projections( spawning_biomass_label = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, tables_dir = getwd() ) diff --git a/man/table_total_catch.Rd b/man/table_total_catch.Rd index 5026642f..e2c94735 100644 --- a/man/table_total_catch.Rd +++ b/man/table_total_catch.Rd @@ -10,6 +10,7 @@ table_total_catch( era = NULL, interactive = TRUE, module = NULL, + model = NULL, scale_amount = 1, digits = 2, make_rda = FALSE, From fa5a5a1bdb3dbef36fb5378421463b05fee069bd Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Tue, 17 Nov 2026 15:54:18 -0500 Subject: [PATCH 09/19] minor docs/code cleanup from review --- R/plot_spawning_biomass.R | 7 ++++--- R/table_landings.R | 2 -- R/table_projections.R | 2 -- R/utils_plot.R | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index 65c7d698..e4f954f5 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -59,7 +59,7 @@ #' #' If the interactive and >1 module_name is found, user will select the #' module_name in the console. @seealso [filter_data()] -#' @param mdoel Character vector. (Optional) Model name found in `dat$model`. +#' @param model Character vector. (Optional) Model name found in `dat$model`. #' If selecting >1 model, place them in a vector like c("model1", "model2"). #' #' Default: NULL @@ -165,7 +165,8 @@ plot_spawning_biomass <- function( module = module, model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # extract unit if unit_label is null and set lbs to F by default lbs <- FALSE @@ -221,7 +222,7 @@ plot_spawning_biomass <- function( group = group, # add check in case facet is returned as character(0) facet = if (length(facet) > 0) facet else NULL, - # ... + ... ) # Add reference line if (relative) { diff --git a/R/table_landings.R b/R/table_landings.R index fe175b20..24ee9ae4 100644 --- a/R/table_landings.R +++ b/R/table_landings.R @@ -196,5 +196,3 @@ table_landings <- function( final } -# table_landings(result) - diff --git a/R/table_projections.R b/R/table_projections.R index 44ddbcba..b9b45284 100644 --- a/R/table_projections.R +++ b/R/table_projections.R @@ -191,5 +191,3 @@ table_projections <- function( final } - -# table_projections(result) diff --git a/R/utils_plot.R b/R/utils_plot.R index 0c5c5c14..573544d8 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -675,7 +675,7 @@ cap_first_letter <- function(s) { #' @inheritParams plot_spawning_biomass #' @param label_name String. Name of the label used to filter #' the data. -#' @param allow_multiple_models Logical. Whetehr to allow multiple models. +#' @param allow_multiple_models Logical. Whether to allow multiple models. #' #' Default: TRUE #' From 525893d5c3aa72c2a4f713c654a19b21363ebca4 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Tue, 17 Nov 2026 15:58:29 -0500 Subject: [PATCH 10/19] docs: update documentation with `model` parameter --- man/filter_data.Rd | 10 +++++++++- man/plot_biomass.Rd | 8 ++++++++ man/plot_discard.Rd | 8 ++++++++ man/plot_fishing_mortality.Rd | 8 ++++++++ man/plot_index.Rd | 8 ++++++++ man/plot_landings.Rd | 8 ++++++++ man/plot_natural_mortality.Rd | 8 ++++++++ man/plot_recruitment.Rd | 8 ++++++++ man/plot_recruitment_deviations.Rd | 8 ++++++++ man/plot_selectivity.Rd | 8 ++++++++ man/plot_spawning_biomass.Rd | 16 ++++++++-------- man/plot_spr.Rd | 8 ++++++++ man/plot_stock_recruitment.Rd | 8 ++++++++ man/table_biomass_abundance_catch.Rd | 8 ++++++++ man/table_index.Rd | 8 ++++++++ man/table_landings.Rd | 8 ++++++++ man/table_projections.Rd | 8 ++++++++ man/table_total_catch.Rd | 8 ++++++++ 18 files changed, 145 insertions(+), 9 deletions(-) diff --git a/man/filter_data.Rd b/man/filter_data.Rd index 9b60be31..c9e3a1b7 100644 --- a/man/filter_data.Rd +++ b/man/filter_data.Rd @@ -36,6 +36,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{era}{String. Era of data. Default: "time" @@ -70,7 +78,7 @@ Default: 1} Default: \code{FALSE}} -\item{allow_multiple_models}{Logical. Whetehr to allow multiple models. +\item{allow_multiple_models}{Logical. Whether to allow multiple models. Default: TRUE} } diff --git a/man/plot_biomass.Rd b/man/plot_biomass.Rd index 3a1c923e..416079d8 100644 --- a/man/plot_biomass.Rd +++ b/man/plot_biomass.Rd @@ -76,6 +76,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the magnitude of the scale amount will be added to the unit label (e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result diff --git a/man/plot_discard.Rd b/man/plot_discard.Rd index 68912086..85f4e40a 100644 --- a/man/plot_discard.Rd +++ b/man/plot_discard.Rd @@ -76,6 +76,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir". diff --git a/man/plot_fishing_mortality.Rd b/man/plot_fishing_mortality.Rd index fa8af9b0..ecc4d0a4 100644 --- a/man/plot_fishing_mortality.Rd +++ b/man/plot_fishing_mortality.Rd @@ -72,6 +72,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir". diff --git a/man/plot_index.Rd b/man/plot_index.Rd index b4e146ae..a21c24cb 100644 --- a/man/plot_index.Rd +++ b/man/plot_index.Rd @@ -53,6 +53,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{focus}{Character vector. Column name or names used to filter data. (i.e. select names of fleets to zoom into the plot). Default = NULL} diff --git a/man/plot_landings.Rd b/man/plot_landings.Rd index 0f70ba9c..82529c02 100644 --- a/man/plot_landings.Rd +++ b/man/plot_landings.Rd @@ -82,6 +82,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: \code{FALSE}} diff --git a/man/plot_natural_mortality.Rd b/man/plot_natural_mortality.Rd index 1d5584c4..dd719185 100644 --- a/man/plot_natural_mortality.Rd +++ b/man/plot_natural_mortality.Rd @@ -53,6 +53,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir". diff --git a/man/plot_recruitment.Rd b/man/plot_recruitment.Rd index d538ad43..f4bb2355 100644 --- a/man/plot_recruitment.Rd +++ b/man/plot_recruitment.Rd @@ -65,6 +65,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir". diff --git a/man/plot_recruitment_deviations.Rd b/man/plot_recruitment_deviations.Rd index ea3cbb24..10011862 100644 --- a/man/plot_recruitment_deviations.Rd +++ b/man/plot_recruitment_deviations.Rd @@ -30,6 +30,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{era}{String. Era of data. Default: "time" diff --git a/man/plot_selectivity.Rd b/man/plot_selectivity.Rd index bfab05a5..4b800bdd 100644 --- a/man/plot_selectivity.Rd +++ b/man/plot_selectivity.Rd @@ -51,6 +51,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir". diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index 0fa2e28d..933c4b6e 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -90,6 +90,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the magnitude of the scale amount will be added to the unit label (e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result @@ -119,14 +127,6 @@ The folder is created within the path if it does not exist.} Default: \code{FALSE}} \item{...}{Arguments called from \link[ggplot2]{geom_line} or \link[ggplot2]{geom_point}} - -\item{mdoel}{Character vector. (Optional) Model name found in \code{dat$model}. -If selecting >1 model, place them in a vector like c("model1", "model2"). - -Default: NULL - -If the interactive and >1 model is found, user will select the -model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} } \value{ A plot showing spawning biomass over time. diff --git a/man/plot_spr.Rd b/man/plot_spr.Rd index 14a3e352..fb577c25 100644 --- a/man/plot_spr.Rd +++ b/man/plot_spr.Rd @@ -73,6 +73,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: \code{FALSE}} diff --git a/man/plot_stock_recruitment.Rd b/man/plot_stock_recruitment.Rd index 742df437..16a52b5c 100644 --- a/man/plot_stock_recruitment.Rd +++ b/man/plot_stock_recruitment.Rd @@ -53,6 +53,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the magnitude of the scale amount will be added to the unit label (e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result diff --git a/man/table_biomass_abundance_catch.Rd b/man/table_biomass_abundance_catch.Rd index a6471d8f..e0f8df67 100644 --- a/man/table_biomass_abundance_catch.Rd +++ b/man/table_biomass_abundance_catch.Rd @@ -78,6 +78,14 @@ in this ordered list: "landings_weight", "landings_numbers", "landings_expected Default: NULL} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir". diff --git a/man/table_index.Rd b/man/table_index.Rd index 46369470..f986ba31 100644 --- a/man/table_index.Rd +++ b/man/table_index.Rd @@ -57,6 +57,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{label}{String. The label that will be chosen from the input file. If unspecified, the function will search the "label" column and use the first matching label in this ordered list: "index_weight", "index_numbers", "index_expected", diff --git a/man/table_landings.Rd b/man/table_landings.Rd index b7bc038e..509a16f4 100644 --- a/man/table_landings.Rd +++ b/man/table_landings.Rd @@ -63,6 +63,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{label}{String or vector of strings. The labels in the "label" column of \code{dat} to tabulate (e.g., "landings_predicted_weight"). If unspecified, the observed landings are used: the first of "landings_observed", diff --git a/man/table_projections.Rd b/man/table_projections.Rd index 68a9407c..b122c685 100644 --- a/man/table_projections.Rd +++ b/man/table_projections.Rd @@ -42,6 +42,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir". diff --git a/man/table_total_catch.Rd b/man/table_total_catch.Rd index e2c94735..ea656a1b 100644 --- a/man/table_total_catch.Rd +++ b/man/table_total_catch.Rd @@ -46,6 +46,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the magnitude of the scale amount will be added to the unit label (e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result From c455b208c004a9422e1f20a9fe8877ba935f2336 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Tue, 17 Nov 2026 16:13:55 -0500 Subject: [PATCH 11/19] docs: update roxygen for interactive filtering --- R/utils_plot.R | 20 +++++++++++++++++++- man/filter_data.Rd | 8 ++++++++ man/filter_interactive.Rd | 12 +++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/R/utils_plot.R b/R/utils_plot.R index 573544d8..c1db7538 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -685,6 +685,14 @@ cap_first_letter <- function(s) { #' @examples #' \dontrun{ #' filter_data(dat, "biomass", "line", group = "fleet") +#' filter_data( +#' dat, +#' label = "biomass", +#' geom = "line", +#' module="derived_quants", +#' model=NULL, +#' allow_multiple_models=FALSE # can only select one model to filter by +#' ) #' } filter_data <- function( dat, @@ -1233,7 +1241,17 @@ add_reference_line <- function( #' #' Default: FALSE #' -#' @return List. filtered data.frame (`plot_data`) and selected option(`selected)` +#' @return List. filtered data.frame (`plot_data`) and selected option(`selected`). +#' +#' @examples +#' \dontrun{ +#' filter_interactive( +#' dat = example_dat, +#' column_name = "model", +#' column_value = NULL, +#' allow_multiple_selection = TRUE # allow selecting multiple models +#' ) +#' } filter_interactive <- function( dat, column_name, diff --git a/man/filter_data.Rd b/man/filter_data.Rd index c9e3a1b7..68e661da 100644 --- a/man/filter_data.Rd +++ b/man/filter_data.Rd @@ -91,5 +91,13 @@ Filter data for input into aesthetics for ggplot2 \examples{ \dontrun{ filter_data(dat, "biomass", "line", group = "fleet") +filter_data( + dat, + label = "biomass", + geom = "line", + module="derived_quants", + model=NULL, + allow_multiple_models=FALSE # can only select one model to filter by +) } } diff --git a/man/filter_interactive.Rd b/man/filter_interactive.Rd index d3be9285..51e46484 100644 --- a/man/filter_interactive.Rd +++ b/man/filter_interactive.Rd @@ -33,9 +33,19 @@ models. Default: FALSE} } \value{ -List. filtered data.frame (\code{plot_data}) and selected option(\verb{selected)} +List. filtered data.frame (\code{plot_data}) and selected option(\code{selected}). } \description{ Allows user to interactively select values from those available to filter their data by. } +\examples{ +\dontrun{ + filter_interactive( + dat = example_dat, + column_name = "model", + column_value = NULL, + allow_multiple_selection = TRUE # allow selecting multiple models + ) +} +} From d4dc8fb55469ce28b49478125f51405e4944f5eb Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Wed, 18 Nov 2026 09:31:06 -0500 Subject: [PATCH 12/19] Update variable names for better readability Changed `kws` to `pretty_columns` --- R/utils_plot.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/utils_plot.R b/R/utils_plot.R index c1db7538..3b075a37 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -1260,7 +1260,7 @@ filter_interactive <- function( allow_multiple_selection = TRUE ){ - kws <- c("module_name"="module", "model"="model") + pretty_columns <- c("module_name"="module", "model"="model") plot_dat <- dat selected <- unique(dat[[column_name]]) @@ -1268,12 +1268,12 @@ filter_interactive <- function( available_names <- unique(dat[[column_name]]) if(!is.null(column_value)){ if(length(column_value) > 1 && !allow_multiple_selection){ - cli::cli_alert_danger("Multiple {kws[column_name]}s provided, but only 1 allowed. Defaulting to first available {kws[column_name]} name: {available_names[1]}.") + cli::cli_alert_danger("Multiple {pretty_columns[column_name]}s provided, but only 1 allowed. Defaulting to first available {pretty_columns[column_name]} name: {available_names[1]}.") } plot_dat <- dat |> dplyr::filter(.data[[column_name]] %in% column_value) selected <- column_value }else{ - cli::cli_alert_warning("Multiple {kws[column_name]}s found in data. \n") + cli::cli_alert_warning("Multiple {pretty_columns[column_name]}s found in data. \n") options <- c() for (i in seq_along(available_names)) { # options <- paste0(options, " ", i, ") ", unique(plot_data$module_name)[i], "\n") @@ -1289,7 +1289,7 @@ filter_interactive <- function( selection <- utils::select.list( options, multiple=allow_multiple_selection, - title = glue::glue("Select one of the following {kws[column_name]} names") + title = glue::glue("Select one of the following {pretty_columns[column_name]} names") ) question1 <- if(length(selection)==0 || identical(selection, "")){ options[1] From e8dbc4271ca676395333a958e9a5c36ffd3bd2e8 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Wed, 18 Nov 2026 13:29:58 -0500 Subject: [PATCH 13/19] docs: correct missing documentation --- R/plot_abundance_at_age.R | 7 +++++++ R/utils_plot.R | 3 +-- man/filter_interactive.Rd | 3 +-- man/plot_abundance_at_age.Rd | 8 ++++++++ man/plot_biomass_at_age.Rd | 8 ++++++++ man/plot_catch_at_age.Rd | 8 ++++++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index c7977171..753f9718 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -35,6 +35,13 @@ #' #' If the interactive and >1 module_name is found, user will select the #' module_name in the console. @seealso [filter_data()] +#' @param model Character vector. (Optional) Model name found in `dat$model`. +#' If selecting >1 model, place them in a vector like c("model1", "model2"). +#' +#' Default: NULL +#' +#' If the interactive and >1 model is found, user will select the +#' model in the console. @seealso [filter_data()] #' @param interactive A logical value indicating if the environment is interactive. #' #' Default: `FALSE` diff --git a/R/utils_plot.R b/R/utils_plot.R index 3b075a37..ca807d04 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -1236,8 +1236,7 @@ add_reference_line <- function( #' #' Default: TRUE #' -#' @param allow_multiple_models Logical. Whether to allow the selection of multiple -#' models. +#' @param allow_multiple_selection Logical. Whether to allow the selection of multiple inputs. #' #' Default: FALSE #' diff --git a/man/filter_interactive.Rd b/man/filter_interactive.Rd index 51e46484..cc6944ff 100644 --- a/man/filter_interactive.Rd +++ b/man/filter_interactive.Rd @@ -27,8 +27,7 @@ Default: NULL} Default: TRUE} -\item{allow_multiple_models}{Logical. Whether to allow the selection of multiple -models. +\item{allow_multiple_selection}{Logical. Whether to allow the selection of multiple inputs. Default: FALSE} } diff --git a/man/plot_abundance_at_age.Rd b/man/plot_abundance_at_age.Rd index 67ab8443..bf6188e2 100644 --- a/man/plot_abundance_at_age.Rd +++ b/man/plot_abundance_at_age.Rd @@ -55,6 +55,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{interactive}{A logical value indicating if the environment is interactive. Default: \code{FALSE}} diff --git a/man/plot_biomass_at_age.Rd b/man/plot_biomass_at_age.Rd index c30b4eba..99e15c73 100644 --- a/man/plot_biomass_at_age.Rd +++ b/man/plot_biomass_at_age.Rd @@ -53,6 +53,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment in which the function is operating is interactive. This bypasses some options for filtering when preparing data for the plot. diff --git a/man/plot_catch_at_age.Rd b/man/plot_catch_at_age.Rd index 05130a44..87a0202b 100644 --- a/man/plot_catch_at_age.Rd +++ b/man/plot_catch_at_age.Rd @@ -66,6 +66,14 @@ Default: NULL If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to produce an .rda file containing a list with the figure/table, caption, and alternative text (if figure). If TRUE, the .rda will be exported to the folder indicated in the argument "rda_dir". From 83f2e1b3ed8fc0f0c105eedabb36e3324c8c76e3 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Wed, 18 Nov 2026 16:25:44 -0500 Subject: [PATCH 14/19] [fix]: disable multi model selection for table_index Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- R/table_index.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/table_index.R b/R/table_index.R index 05e356a4..1f4129f7 100644 --- a/R/table_index.R +++ b/R/table_index.R @@ -72,7 +72,8 @@ table_index <- function( module = module, model = model, scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) |> dplyr::mutate( estimate = round(as.numeric(estimate), digits = digits), From 56e99dd1243d0d079e2ded5960be7063f83fab65 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Wed, 18 Nov 2026 16:40:19 -0500 Subject: [PATCH 15/19] fix: fix bug when making multiple selections INCLUDING "All" --- R/utils_plot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils_plot.R b/R/utils_plot.R index ca807d04..d52b849c 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -1292,7 +1292,7 @@ filter_interactive <- function( ) question1 <- if(length(selection)==0 || identical(selection, "")){ options[1] - }else if(selection=="All"){ + }else if("All" %in% selection){ options[-length(options)] }else{ selection From c8e7177564c53e6cf13bd56fd109c645bb169da8 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Wed, 18 Nov 2026 16:42:42 -0500 Subject: [PATCH 16/19] fix: make sure only first value ends up selectd if multiple supplied and allow_multiple_selection=FALSE --- R/utils_plot.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/utils_plot.R b/R/utils_plot.R index d52b849c..7f2e00b1 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -1268,6 +1268,7 @@ filter_interactive <- function( if(!is.null(column_value)){ if(length(column_value) > 1 && !allow_multiple_selection){ cli::cli_alert_danger("Multiple {pretty_columns[column_name]}s provided, but only 1 allowed. Defaulting to first available {pretty_columns[column_name]} name: {available_names[1]}.") + column_value <- available_names[1] } plot_dat <- dat |> dplyr::filter(.data[[column_name]] %in% column_value) selected <- column_value From 7d3fe3b31aa186988b5788d28397eefd0af87104 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Wed, 18 Nov 2026 16:44:57 -0500 Subject: [PATCH 17/19] fix: pass model on to filter_data in table_total_catch --- R/table_total_catch.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/table_total_catch.R b/R/table_total_catch.R index ae36535e..c5283f89 100644 --- a/R/table_total_catch.R +++ b/R/table_total_catch.R @@ -64,7 +64,7 @@ table_total_catch <- function( geom = "line", era = era, module = module, - model = NULL, + model = model, scale_amount = scale_amount, interactive = interactive, allow_multiple_models = FALSE From ba4e1a94918c9ca39654b3dd96c1de011123125f Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Wed, 18 Nov 2026 16:51:32 -0500 Subject: [PATCH 18/19] fix: handle multiple reference lines in plot_biomass when multiple models present --- R/plot_biomass.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/plot_biomass.R b/R/plot_biomass.R index 1e144498..15e2c7e5 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -158,7 +158,7 @@ plot_biomass <- function( } else { final <- plt + add_reference_line( - dat = dat, + dat = dat |> dplyr::filter(model %in% selected_model), ref_line = ref_line, label = "biomass", scale_amount = scale_amount From cf9fe02c7c17fbc617ef0aeac03032f92a693c4e Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Wed, 18 Nov 2026 18:02:05 -0500 Subject: [PATCH 19/19] fix: can't use model="All" directly with `filter_data` --- R/plot_retrospective.R | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/R/plot_retrospective.R b/R/plot_retrospective.R index fea5df17..86fdada0 100644 --- a/R/plot_retrospective.R +++ b/R/plot_retrospective.R @@ -141,9 +141,9 @@ plot_retrospective <- function( func_pars <- list( dat = retro_dat, group="peel", - model = "All", # turn this on to bypass interactive model selection and plot all available models - make_rda=FALSE, # don't want to overwrite files from non-retro plots - ... + model = names(end_years), # turn this on to bypass interactive model selection and plot all available models + make_rda=FALSE # don't want to overwrite files from non-retro plots + # ... ) plt <- do.call(func_name, func_pars) @@ -226,5 +226,3 @@ plot_retrospective <- function( plt } - -# plot_retrospective(dat)