From 1a80f96ffe53fa81a14f2f82e85766dc271e52b8 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Fri, 27 Nov 2026 10:42:27 -0500 Subject: [PATCH 1/7] refactor: make "All" the default model selection When multiple models are present in the data teh default choice is now "All" rather than the first available model. --- R/utils_plot.R | 50 +++++++++++++++++++++------------------ man/filter_interactive.Rd | 9 ++++--- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/R/utils_plot.R b/R/utils_plot.R index 7e26d639..e90bf228 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -659,6 +659,8 @@ cap_first_letter <- function(s) { #' @param label_name String. Name of the label used to filter #' the data. #' @param allow_multiple_models Logical. Whether to allow multiple models. +#' When FALSE and `model` is NULL, one model is selected interactively or the +#' first is used in non-interactive mode. #' #' Default: TRUE #' @@ -690,7 +692,7 @@ filter_data <- function( interactive = TRUE, allow_multiple_models = TRUE ) { - # Check if there are multiple module_names present + # Filter by model before selecting a module. model_select <- filter_interactive( dat, column_name = "model", @@ -1210,8 +1212,9 @@ add_reference_line <- function( #' #' @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. +#' @param column_value Character vector. Values of the column to filter by. If NULL, +#' selection is interactive when possible. The default is all models when multiple +#' model selection is allowed, and the first value otherwise. #' #' Default: NULL #' @@ -1221,7 +1224,7 @@ add_reference_line <- function( #' #' @param allow_multiple_selection Logical. Whether to allow the selection of multiple inputs. #' -#' Default: FALSE +#' Default: TRUE #' #' @return List. filtered data.frame (`plot_data`) and selected option(`selected`). #' @@ -1243,55 +1246,56 @@ filter_interactive <- function( ) { pretty_columns <- c("module_name" = "module", "model" = "model") + default_all <- column_name == "model" && allow_multiple_selection + plot_dat <- dat selected <- unique(dat[[column_name]]) - if (length(unique(dat[[column_name]])) > 1) { + if (length(selected) > 1) { available_names <- unique(dat[[column_name]]) if (!is.null(column_value)) { - if (length(column_value) > 1 && !allow_multiple_selection) { + if ((length(column_value) > 1 || (column_name == "model" && "All" %in% column_value)) && !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 + selected <- if (default_all && "All" %in% column_value) available_names else column_value + plot_dat <- dat |> dplyr::filter(.data[[column_name]] %in% selected) } else { 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") - options[i] <- paste0(available_names[i]) - } - if (column_name == "model") { - options <- c(options, "All") - } + options <- as.character(available_names) + if (default_all) options <- c("All", options) if (interactive()) { if (interactive) { selection <- utils::select.list( options, + preselect = if (default_all) "All" else NULL, multiple = allow_multiple_selection, title = glue::glue("Select one of the following {pretty_columns[column_name]} names") ) question1 <- if (length(selection) == 0 || identical(selection, "")) { options[1] - } else if ("All" %in% selection) { - options[-length(options)] } else { selection } - selected <- intersect(available_names, question1) + selected <- if (default_all && identical(question1, "All")) { + available_names + } else if (default_all) { + intersect(available_names, setdiff(question1, "All")) + } else { + 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}.") + selected <- if (default_all) available_names else available_names[1] + cli::cli_alert_info("Selection bypassed. Filtering by {paste(selected, collapse = ', ')}.") } } else { - selected <- available_names[1] - cli::cli_alert_info(glue::glue("Environment not interactive. Selecting {selected}.")) + selected <- if (default_all) available_names else available_names[1] + cli::cli_alert_info(glue::glue("Environment not interactive. Selecting {paste(selected, collapse = ', ')}.")) } if (length(selected) > 0) { plot_dat <- dat |> diff --git a/man/filter_interactive.Rd b/man/filter_interactive.Rd index 92cf024d..c761128e 100644 --- a/man/filter_interactive.Rd +++ b/man/filter_interactive.Rd @@ -18,8 +18,11 @@ 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. +\item{column_value}{Character vector. Values of the column to filter by. For +models, "All" retains all models when multiple selection is allowed. If NULL, +selection is interactive when possible, defaulting to all models when multiple +selection is allowed and the first value otherwise. In the interactive model +menu, selecting specific models overrides the preselected "All" option. Default: NULL} @@ -29,7 +32,7 @@ Default: TRUE} \item{allow_multiple_selection}{Logical. Whether to allow the selection of multiple inputs. -Default: FALSE} +Default: TRUE} } \value{ List. filtered data.frame (\code{plot_data}) and selected option(\code{selected}). From 90e85ae4f9467711f9236922f282966d857e6a3e Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Fri, 27 Nov 2026 10:44:19 -0500 Subject: [PATCH 2/7] refactor: set default model selection for all plots to "All" --- R/plot_abundance_at_age.R | 7 ++----- R/plot_biomass.R | 2 +- R/plot_biomass_at_age.R | 2 +- R/plot_catch_at_age.R | 2 +- R/plot_discard.R | 2 +- R/plot_fishing_mortality.R | 2 +- R/plot_index.R | 2 +- R/plot_landings.R | 2 +- R/plot_natural_mortality.R | 2 +- R/plot_recruitment.R | 2 +- R/plot_recruitment_deviations.R | 2 +- R/plot_selectivity.R | 2 +- R/plot_spawning_biomass.R | 7 ++----- R/plot_spr.R | 2 +- R/plot_stock_recruitment.R | 5 +++-- R/table_biomass_abundance_catch.R | 2 ++ R/table_index.R | 2 ++ R/table_landings.R | 2 ++ R/table_total_catch.R | 2 ++ R/utils_plot.R | 13 ++++++++++--- man/filter_data.Rd | 12 ++++++------ man/plot_abundance_at_age.Rd | 7 ++----- man/plot_biomass.Rd | 7 ++----- man/plot_biomass_at_age.Rd | 7 ++----- man/plot_catch_at_age.Rd | 7 ++----- man/plot_discard.Rd | 7 ++----- man/plot_fishing_mortality.Rd | 7 ++----- man/plot_index.Rd | 7 ++----- man/plot_landings.Rd | 7 ++----- man/plot_natural_mortality.Rd | 7 ++----- man/plot_recruitment.Rd | 7 ++----- man/plot_recruitment_deviations.Rd | 7 ++----- man/plot_selectivity.Rd | 7 ++----- man/plot_spawning_biomass.Rd | 7 ++----- man/plot_spr.Rd | 7 ++----- man/plot_stock_recruitment.Rd | 7 ++----- man/table_biomass_abundance_catch.Rd | 9 ++------- man/table_index.Rd | 9 ++------- man/table_landings.Rd | 9 ++------- man/table_projections.Rd | 9 ++------- man/table_total_catch.Rd | 9 ++------- 41 files changed, 83 insertions(+), 143 deletions(-) diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index 9c77aebb..322681db 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -38,10 +38,7 @@ #' @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()] +#' Default: "All" (all models). Set to NULL for interactive selection when available. #' @param interactive A logical value indicating if the environment is interactive. #' #' Default: `FALSE` @@ -88,7 +85,7 @@ plot_abundance_at_age <- function( scale_amount = 1, proportional = TRUE, module = NULL, - model = NULL, + model = "All", interactive = TRUE, make_rda = FALSE, figures_dir = getwd() diff --git a/R/plot_biomass.R b/R/plot_biomass.R index fdd14630..4488f4c9 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -50,7 +50,7 @@ plot_biomass <- function( era = NULL, unit_label = NULL, module = NULL, - model = NULL, + model = "All", scale_amount = 1, relative = FALSE, make_rda = FALSE, diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index 9d5d0af7..4a43f1e7 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -46,7 +46,7 @@ plot_biomass_at_age <- function( scale_amount = 1, proportional = TRUE, module = NULL, - model = NULL, + model = "All", interactive = TRUE, make_rda = FALSE, figures_dir = getwd() diff --git a/R/plot_catch_at_age.R b/R/plot_catch_at_age.R index 5d403476..72c10b7d 100644 --- a/R/plot_catch_at_age.R +++ b/R/plot_catch_at_age.R @@ -74,7 +74,7 @@ plot_catch_at_age <- function( proportional = TRUE, interactive = TRUE, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd() ) { diff --git a/R/plot_discard.R b/R/plot_discard.R index 76f49e72..ad7615cc 100644 --- a/R/plot_discard.R +++ b/R/plot_discard.R @@ -87,7 +87,7 @@ plot_discard <- function( scale_amount = 1, interactive = TRUE, module = NULL, - model = NULL, + model = "All", predicted = TRUE, interval = 0.95, tolerance = 0.001, diff --git a/R/plot_fishing_mortality.R b/R/plot_fishing_mortality.R index a33f94cd..c10d8f81 100644 --- a/R/plot_fishing_mortality.R +++ b/R/plot_fishing_mortality.R @@ -36,7 +36,7 @@ plot_fishing_mortality <- function( ref_line = "msy", era = NULL, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd(), interactive = TRUE, diff --git a/R/plot_index.R b/R/plot_index.R index 22007a44..0d70caf6 100644 --- a/R/plot_index.R +++ b/R/plot_index.R @@ -75,7 +75,7 @@ plot_index <- function( facet = NULL, interactive = TRUE, module = NULL, - model = NULL, + model = "All", focus = NULL, interval = 0.95, log = FALSE, diff --git a/R/plot_landings.R b/R/plot_landings.R index 4749e545..ab830d53 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -97,7 +97,7 @@ plot_landings <- function( era = NULL, scale_amount = 1, module = NULL, - model = NULL, + model = "All", interactive = TRUE, predicted = TRUE, interval = 0.95, diff --git a/R/plot_natural_mortality.R b/R/plot_natural_mortality.R index 375c144e..0b00506c 100644 --- a/R/plot_natural_mortality.R +++ b/R/plot_natural_mortality.R @@ -26,7 +26,7 @@ plot_natural_mortality <- function( era = NULL, interactive = TRUE, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd(), ... diff --git a/R/plot_recruitment.R b/R/plot_recruitment.R index ced98abd..d68de69a 100644 --- a/R/plot_recruitment.R +++ b/R/plot_recruitment.R @@ -42,7 +42,7 @@ plot_recruitment <- function( # relative = FALSE, interactive = TRUE, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd() ) { diff --git a/R/plot_recruitment_deviations.R b/R/plot_recruitment_deviations.R index 72122986..306a8f46 100644 --- a/R/plot_recruitment_deviations.R +++ b/R/plot_recruitment_deviations.R @@ -33,7 +33,7 @@ plot_recruitment_deviations <- function( dat, module = NULL, - model = NULL, + model = "All", era = NULL, interactive = TRUE, make_rda = FALSE, diff --git a/R/plot_selectivity.R b/R/plot_selectivity.R index 48169f13..4a75d090 100644 --- a/R/plot_selectivity.R +++ b/R/plot_selectivity.R @@ -37,7 +37,7 @@ plot_selectivity <- function( facet = NULL, interactive = TRUE, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd(), ... diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index 7dea2b04..4fe58dc8 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -62,10 +62,7 @@ #' @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()] +#' Default: "All" (all models). Set to NULL for interactive selection when available. #' @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 @@ -139,7 +136,7 @@ plot_spawning_biomass <- function( era = NULL, lbs = lifecycle::deprecated(), module = NULL, - model = NULL, + model = "All", scale_amount = 1, relative = FALSE, make_rda = FALSE, diff --git a/R/plot_spr.R b/R/plot_spr.R index 01d786c0..188af650 100644 --- a/R/plot_spr.R +++ b/R/plot_spr.R @@ -41,7 +41,7 @@ plot_spr <- function( ref_line = "target", era = NULL, module = NULL, - model = NULL, + model = "All", interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), diff --git a/R/plot_stock_recruitment.R b/R/plot_stock_recruitment.R index b5444773..76074179 100644 --- a/R/plot_stock_recruitment.R +++ b/R/plot_stock_recruitment.R @@ -43,7 +43,7 @@ plot_stock_recruitment <- function( interactive = TRUE, era = NULL, module = NULL, - model = NULL, + model = "All", scale_amount = 1, make_rda = FALSE, figures_dir = getwd() @@ -106,7 +106,8 @@ plot_stock_recruitment <- function( era = era, scale_amount = scale_amount, interactive = interactive, - module = module + module = module, + model = selected_model ) process_sb <- process_data( diff --git a/R/table_biomass_abundance_catch.R b/R/table_biomass_abundance_catch.R index 70997228..2206935a 100644 --- a/R/table_biomass_abundance_catch.R +++ b/R/table_biomass_abundance_catch.R @@ -1,6 +1,8 @@ #' Biomass, abundance, and catch time series table #' #' @inheritParams plot_recruitment +#' @param model Character. Model name found in `dat$model`. If NULL, one model +#' is selected interactively when possible, or the first available model is used. #' #' @param biomass_label String. Units for biomass #' diff --git a/R/table_index.R b/R/table_index.R index 3efdf5f1..5e5b64e8 100644 --- a/R/table_index.R +++ b/R/table_index.R @@ -1,6 +1,8 @@ #' Index of abundance table #' #' @inheritParams plot_recruitment +#' @param model Character. Model name found in `dat$model`. If NULL, one model +#' is selected interactively when possible, or the first available model is used. #' @param group String. Single column that groups the data. #' #' Set group = "none" to summarize data over all indexing values. diff --git a/R/table_landings.R b/R/table_landings.R index 977cda14..3bd1133a 100644 --- a/R/table_landings.R +++ b/R/table_landings.R @@ -1,6 +1,8 @@ #' Landed catch by fleet and year table #' #' @inheritParams plot_recruitment +#' @param model Character. Model name found in `dat$model`. If NULL, one model +#' is selected interactively when possible, or the first available model is used. #' @param unit_label String. Abbreviated landings units #' #' Default: NULL diff --git a/R/table_total_catch.R b/R/table_total_catch.R index 92caaea0..90ff6ea7 100644 --- a/R/table_total_catch.R +++ b/R/table_total_catch.R @@ -1,6 +1,8 @@ #' Catch (table) by fleet, gear type, sector #' #' @inheritParams plot_recruitment +#' @param model Character. Model name found in `dat$model`. If NULL, one model +#' is selected interactively when possible, or the first available model is used. #' @param unit_label String. Abbreviated catch units #' #' Default: NULL diff --git a/R/utils_plot.R b/R/utils_plot.R index e90bf228..dbb87108 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -658,6 +658,11 @@ cap_first_letter <- function(s) { #' @inheritParams plot_spawning_biomass #' @param label_name String. Name of the label used to filter #' the data. +#' @param model Character vector. Model names to retain, or "All" to retain +#' all models when multiple models are allowed. If NULL, selection is interactive +#' when possible and otherwise defaults to all models when allowed, or the first. +#' +#' Default: NULL #' @param allow_multiple_models Logical. Whether to allow multiple models. #' When FALSE and `model` is NULL, one model is selected interactively or the #' first is used in non-interactive mode. @@ -1212,9 +1217,11 @@ add_reference_line <- function( #' #' @param column_name String. Name of the column to allow interactive filtering for. #' -#' @param column_value Character vector. Values of the column to filter by. If NULL, -#' selection is interactive when possible. The default is all models when multiple -#' model selection is allowed, and the first value otherwise. +#' @param column_value Character vector. Values of the column to filter by. For +#' models, "All" retains all models when multiple selection is allowed. If NULL, +#' selection is interactive when possible, defaulting to all models when multiple +#' selection is allowed and the first value otherwise. In the interactive model +#' menu, selecting specific models overrides the preselected "All" option. #' #' Default: NULL #' diff --git a/man/filter_data.Rd b/man/filter_data.Rd index 3168a2f4..09ea22cc 100644 --- a/man/filter_data.Rd +++ b/man/filter_data.Rd @@ -36,13 +36,11 @@ 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"). +\item{model}{Character vector. Model names to retain, or "All" to retain +all models when multiple models are allowed. If NULL, selection is interactive +when possible and otherwise defaults to all models when allowed, or the first. -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()}}} +Default: NULL} \item{era}{String. Era of data. @@ -79,6 +77,8 @@ Default: 1} Default: \code{FALSE}} \item{allow_multiple_models}{Logical. Whether to allow multiple models. +When FALSE and \code{model} is NULL, one model is selected interactively or the +first is used in non-interactive mode. Default: TRUE} } diff --git a/man/plot_abundance_at_age.Rd b/man/plot_abundance_at_age.Rd index bf6188e2..693d5adc 100644 --- a/man/plot_abundance_at_age.Rd +++ b/man/plot_abundance_at_age.Rd @@ -11,7 +11,7 @@ plot_abundance_at_age( scale_amount = 1, proportional = TRUE, module = NULL, - model = NULL, + model = "All", interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -58,10 +58,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \item{interactive}{A logical value indicating if the environment is interactive. diff --git a/man/plot_biomass.Rd b/man/plot_biomass.Rd index 416079d8..9231256c 100644 --- a/man/plot_biomass.Rd +++ b/man/plot_biomass.Rd @@ -13,7 +13,7 @@ plot_biomass( era = NULL, unit_label = NULL, module = NULL, - model = NULL, + model = "All", scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -79,10 +79,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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 diff --git a/man/plot_biomass_at_age.Rd b/man/plot_biomass_at_age.Rd index 99e15c73..1b4ef4d6 100644 --- a/man/plot_biomass_at_age.Rd +++ b/man/plot_biomass_at_age.Rd @@ -11,7 +11,7 @@ plot_biomass_at_age( scale_amount = 1, proportional = TRUE, module = NULL, - model = NULL, + model = "All", interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -56,10 +56,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment in which the function is operating is interactive. This bypasses some options for diff --git a/man/plot_catch_at_age.Rd b/man/plot_catch_at_age.Rd index df5059fd..784e4bc2 100644 --- a/man/plot_catch_at_age.Rd +++ b/man/plot_catch_at_age.Rd @@ -13,7 +13,7 @@ plot_catch_at_age( proportional = TRUE, interactive = TRUE, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd() ) @@ -69,10 +69,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_discard.Rd b/man/plot_discard.Rd index caca4458..1b951610 100644 --- a/man/plot_discard.Rd +++ b/man/plot_discard.Rd @@ -15,7 +15,7 @@ plot_discard( scale_amount = 1, interactive = TRUE, module = NULL, - model = NULL, + model = "All", predicted = TRUE, interval = 0.95, tolerance = 0.001, @@ -92,10 +92,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \item{predicted}{Logical. TRUE (Default) or FALSE; show the discards predicted by the model as lines, with the observed discards as points, to diff --git a/man/plot_fishing_mortality.Rd b/man/plot_fishing_mortality.Rd index ecc4d0a4..89f60a06 100644 --- a/man/plot_fishing_mortality.Rd +++ b/man/plot_fishing_mortality.Rd @@ -12,7 +12,7 @@ plot_fishing_mortality( ref_line = "msy", era = NULL, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd(), interactive = TRUE, @@ -75,10 +75,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_index.Rd b/man/plot_index.Rd index a21c24cb..f68e7a8d 100644 --- a/man/plot_index.Rd +++ b/man/plot_index.Rd @@ -11,7 +11,7 @@ plot_index( facet = NULL, interactive = TRUE, module = NULL, - model = NULL, + model = "All", focus = NULL, interval = 0.95, log = FALSE, @@ -56,10 +56,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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 2134758b..a8995661 100644 --- a/man/plot_landings.Rd +++ b/man/plot_landings.Rd @@ -14,7 +14,7 @@ plot_landings( era = NULL, scale_amount = 1, module = NULL, - model = NULL, + model = "All", interactive = TRUE, predicted = TRUE, interval = 0.95, @@ -88,10 +88,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. diff --git a/man/plot_natural_mortality.Rd b/man/plot_natural_mortality.Rd index dd719185..6e1795ba 100644 --- a/man/plot_natural_mortality.Rd +++ b/man/plot_natural_mortality.Rd @@ -11,7 +11,7 @@ plot_natural_mortality( era = NULL, interactive = TRUE, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd(), ... @@ -56,10 +56,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_recruitment.Rd b/man/plot_recruitment.Rd index f4bb2355..c71cf597 100644 --- a/man/plot_recruitment.Rd +++ b/man/plot_recruitment.Rd @@ -13,7 +13,7 @@ plot_recruitment( facet = NULL, interactive = TRUE, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd() ) @@ -68,10 +68,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_recruitment_deviations.Rd b/man/plot_recruitment_deviations.Rd index 10011862..a187217c 100644 --- a/man/plot_recruitment_deviations.Rd +++ b/man/plot_recruitment_deviations.Rd @@ -7,7 +7,7 @@ plot_recruitment_deviations( dat, module = NULL, - model = NULL, + model = "All", era = NULL, interactive = TRUE, make_rda = FALSE, @@ -33,10 +33,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \item{era}{String. Era of data. diff --git a/man/plot_selectivity.Rd b/man/plot_selectivity.Rd index 4b800bdd..de8af024 100644 --- a/man/plot_selectivity.Rd +++ b/man/plot_selectivity.Rd @@ -11,7 +11,7 @@ plot_selectivity( facet = NULL, interactive = TRUE, module = NULL, - model = NULL, + model = "All", make_rda = FALSE, figures_dir = getwd(), ... @@ -54,10 +54,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index 933c4b6e..18ec4610 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -14,7 +14,7 @@ plot_spawning_biomass( era = NULL, lbs = lifecycle::deprecated(), module = NULL, - model = NULL, + model = "All", scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -93,10 +93,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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 diff --git a/man/plot_spr.Rd b/man/plot_spr.Rd index d63d670d..a9cde6d3 100644 --- a/man/plot_spr.Rd +++ b/man/plot_spr.Rd @@ -12,7 +12,7 @@ plot_spr( ref_line = "target", era = NULL, module = NULL, - model = NULL, + model = "All", interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), @@ -76,10 +76,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. diff --git a/man/plot_stock_recruitment.Rd b/man/plot_stock_recruitment.Rd index 16a52b5c..47ae2d66 100644 --- a/man/plot_stock_recruitment.Rd +++ b/man/plot_stock_recruitment.Rd @@ -11,7 +11,7 @@ plot_stock_recruitment( interactive = TRUE, era = NULL, module = NULL, - model = NULL, + model = "All", scale_amount = 1, make_rda = FALSE, figures_dir = getwd() @@ -56,10 +56,7 @@ 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()}}} +Default: "All" (all models). Set to NULL for interactive selection when available.} \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 diff --git a/man/table_biomass_abundance_catch.Rd b/man/table_biomass_abundance_catch.Rd index e0f8df67..fc857486 100644 --- a/man/table_biomass_abundance_catch.Rd +++ b/man/table_biomass_abundance_catch.Rd @@ -78,13 +78,8 @@ 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{model}{Character. Model name found in \code{dat$model}. If NULL, one model +is selected interactively when possible, or the first available model is used.} \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, diff --git a/man/table_index.Rd b/man/table_index.Rd index f986ba31..7bcbc2e8 100644 --- a/man/table_index.Rd +++ b/man/table_index.Rd @@ -57,13 +57,8 @@ 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{model}{Character. Model name found in \code{dat$model}. If NULL, one model +is selected interactively when possible, or the first available model is used.} \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 diff --git a/man/table_landings.Rd b/man/table_landings.Rd index 509a16f4..fc7f39b6 100644 --- a/man/table_landings.Rd +++ b/man/table_landings.Rd @@ -63,13 +63,8 @@ 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{model}{Character. Model name found in \code{dat$model}. If NULL, one model +is selected interactively when possible, or the first available model is used.} \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, diff --git a/man/table_projections.Rd b/man/table_projections.Rd index b122c685..4390a574 100644 --- a/man/table_projections.Rd +++ b/man/table_projections.Rd @@ -42,13 +42,8 @@ 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{model}{Character. Model name found in \code{dat$model}. If NULL, one model +is selected interactively when possible, or the first available model is used.} \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, diff --git a/man/table_total_catch.Rd b/man/table_total_catch.Rd index ea656a1b..9ccb023b 100644 --- a/man/table_total_catch.Rd +++ b/man/table_total_catch.Rd @@ -46,13 +46,8 @@ 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{model}{Character. Model name found in \code{dat$model}. If NULL, one model +is selected interactively when possible, or the first available model is used.} \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 From ae39001cc3d3fd49706683bc23265d1d4a806195 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Fri, 27 Nov 2026 10:45:12 -0500 Subject: [PATCH 3/7] tests: add tests for default "all" model selection --- R/process_data.R | 1 + tests/testthat/test-plot_spawning_biomass.R | 41 +++++++ tests/testthat/test-plot_stock_recruitment.R | 13 +++ tests/testthat/test-utils_plot.R | 116 +++++++++++++++++++ 4 files changed, 171 insertions(+) diff --git a/R/process_data.R b/R/process_data.R index ad0c1b98..5fcee3f6 100644 --- a/R/process_data.R +++ b/R/process_data.R @@ -236,6 +236,7 @@ process_data <- function( } # close length index_vars > 0 if (!is.null(group) && group != "none") { + data <- dplyr::mutate(data, group_var = .data[[group]]) # check if value varies in ANY year # pivot data for 1st indexed data and check if all the same if (length(index_variables) > 0) { diff --git a/tests/testthat/test-plot_spawning_biomass.R b/tests/testthat/test-plot_spawning_biomass.R index 97303c2f..8f246963 100644 --- a/tests/testthat/test-plot_spawning_biomass.R +++ b/tests/testthat/test-plot_spawning_biomass.R @@ -40,6 +40,47 @@ test_that("plot_spawning_biomass generates plots without errors", { ) }) +test_that("plot_spawning_biomass plots all models by default", { + testthat::local_mocked_bindings(interactive = function() TRUE, .package = "base") + testthat::local_mocked_bindings( + select.list = function(...) stop("Unexpected selection prompt"), + .package = "utils" + ) + dat <- dplyr::bind_rows( + dplyr::mutate(stockplotr::example_data, model = "model1"), + dplyr::mutate(stockplotr::example_data, model = "model2", estimate=estimate*1.5) + ) + plot <- plot_spawning_biomass( + dat, module = "TIME_SERIES", unit_label = "mt", + ref_line = c("msy" = 2000000), interactive = TRUE + ) + expect_setequal(unique(plot$layers[[2]]$data$model), c("model1", "model2")) + expect_length(unique(ggplot2::ggplot_build(plot)$data[[2]]$group), 2) + + plot <- plot_spawning_biomass( + dat, module = "TIME_SERIES", model = "model2", unit_label = "mt", + ref_line = c("msy" = 2000000), interactive = FALSE + ) + expect_equal(unique(plot$layers[[2]]$data$model), "model2") +}) + +test_that("interactive model selection limits the plot", { + testthat::local_mocked_bindings(interactive = function() TRUE, .package = "base") + testthat::local_mocked_bindings( + select.list = function(...) c("All", "model2"), + .package = "utils" + ) + dat <- dplyr::bind_rows( + dplyr::mutate(stockplotr::example_data, model = "model1"), + dplyr::mutate(stockplotr::example_data, model = "model2") + ) + plot <- plot_spawning_biomass( + dat, module = "TIME_SERIES", model = NULL, interactive = TRUE, + unit_label = "mt", ref_line = c("msy" = 2000000) + ) + expect_equal(unique(plot$layers[[2]]$data$model), "model2") +}) + # test_that("rda file made when indicated", { # # export rda # plot_spawning_biomass( diff --git a/tests/testthat/test-plot_stock_recruitment.R b/tests/testthat/test-plot_stock_recruitment.R index b918730f..96d61af0 100644 --- a/tests/testthat/test-plot_stock_recruitment.R +++ b/tests/testthat/test-plot_stock_recruitment.R @@ -34,6 +34,19 @@ test_that("plot_stock_recruitment generates plots without errors", { ) }) +test_that("stock recruitment uses the selected models for both series", { + dat <- dplyr::bind_rows( + dplyr::mutate(stockplotr::example_data, model = "model1"), + dplyr::mutate(stockplotr::example_data, model = "model2") + ) + plot <- plot_stock_recruitment( + dat, model = "model2", interactive = FALSE, + spawning_biomass_label = "mt", recruitment_label = "mt" + ) + expect_equal(unique(plot$layers[[1]]$data$model), "model2") + expect_true(any(!is.na(plot$layers[[1]]$data$predicted_recruitment))) +}) + # test_that("rda file made when indicated", { # # export rda # plot_stock_recruitment( diff --git a/tests/testthat/test-utils_plot.R b/tests/testthat/test-utils_plot.R index f75b25f1..8f5d5ada 100644 --- a/tests/testthat/test-utils_plot.R +++ b/tests/testthat/test-utils_plot.R @@ -69,6 +69,122 @@ test_that("filter_data handles data frames", { expect_setequal(unique(filtered_list$group_var), c("model_one", "model_two")) }) +test_that("model defaults retain all models in interactive and non-interactive modes", { + testthat::local_mocked_bindings( + interactive = function() TRUE, + .package = "base" + ) + choices_seen <- NULL + preselect_seen <- NULL + selection <- character(0) + testthat::local_mocked_bindings(select.list = function(choices, preselect, ...) { + choices_seen <<- choices + preselect_seen <<- preselect + selection + }, .package = "utils") + + dat <- make_utils_plot_multimodel_data() + for (interactive in c(TRUE, FALSE)) { + filtered <- filter_data( + dat = dat, + label_name = "^biomass$", + geom = "line", + interactive = interactive + ) + expect_setequal(unique(filtered$model), c("model_one", "model_two")) + expect_setequal(unique(filtered$group_var), c("model_one", "model_two")) + expect_setequal(get("selected_model", envir = .GlobalEnv), c("model_one", "model_two")) + } + expect_equal(choices_seen, c("All", "model_one", "model_two")) + expect_equal(preselect_seen, "All") + + selection <- "All" + filtered <- filter_data( + dat = dat, label_name = "^biomass$", geom = "line", interactive = TRUE + ) + expect_setequal(unique(filtered$model), c("model_one", "model_two")) + + selection <- "model_two" + filtered <- filter_data( + dat = dat, label_name = "^biomass$", geom = "line", interactive = TRUE + ) + expect_equal(unique(filtered$model), "model_two") + + selection <- c("All", "model_two") + filtered <- filter_data( + dat = dat, label_name = "^biomass$", geom = "line", interactive = TRUE + ) + expect_equal(unique(filtered$model), "model_two") + expect_equal(get("selected_model", envir = .GlobalEnv), "model_two") + + filtered <- filter_data( + dat = dat, label_name = "^biomass$", geom = "line", + model = "model_two", interactive = TRUE + ) + expect_equal(unique(filtered$model), "model_two") +}) + +test_that("specific interactive model selections override All", { + testthat::local_mocked_bindings(interactive = function() TRUE, .package = "base") + testthat::local_mocked_bindings( + select.list = function(...) c("All", "model_two", "model_three"), + .package = "utils" + ) + dat <- tibble::tibble(model = c("model_one", "model_two", "model_three", "model_four")) + selected <- stockplotr:::filter_interactive(dat, "model", interactive = TRUE) + expect_equal(selected$selected, c("model_two", "model_three")) + expect_equal(selected$plot_data$model, c("model_two", "model_three")) +}) + +test_that("model defaults retain all models when the environment is non-interactive", { + testthat::local_mocked_bindings(interactive = function() FALSE, .package = "base") + for (interactive in c(TRUE, FALSE)) { + selected <- stockplotr:::filter_interactive( + make_utils_plot_multimodel_data(), "model", interactive = interactive + ) + expect_setequal(unique(selected$plot_data$model), c("model_one", "model_two")) + expect_setequal(selected$selected, c("model_one", "model_two")) + } +}) + +test_that("All selects every model but remains a literal module name", { + dat <- make_utils_plot_multimodel_data() + selected <- stockplotr:::filter_interactive(dat, "model", column_value = "All") + expect_identical(selected$plot_data, dat) + expect_equal(selected$selected, c("model_one", "model_two")) + + modules <- tibble::tibble(module_name = c("All", "OTHER")) + selected <- stockplotr:::filter_interactive(modules, "module_name", column_value = "All") + expect_equal(selected$plot_data$module_name, "All") + expect_equal(selected$selected, "All") +}) + +test_that("single-model selection and module selection retain their defaults", { + dat <- make_utils_plot_multimodel_data() + selected <- stockplotr:::filter_interactive( + dat, "model", interactive = FALSE, allow_multiple_selection = FALSE + ) + expect_equal(unique(selected$plot_data$model), "model_one") + expect_equal(selected$selected, "model_one") + + testthat::local_mocked_bindings(interactive = function() TRUE, .package = "base") + testthat::local_mocked_bindings( + select.list = function(...) "model_two", + .package = "utils" + ) + selected <- stockplotr:::filter_interactive( + dat, "model", interactive = TRUE, allow_multiple_selection = FALSE + ) + expect_equal(unique(selected$plot_data$model), "model_two") + expect_equal(selected$selected, "model_two") + + modules <- make_utils_plot_multimodule_data() + selected <- stockplotr:::filter_interactive( + modules, "module_name", interactive = FALSE, allow_multiple_selection = TRUE + ) + expect_equal(unique(selected$plot_data$module_name), "TIME_SERIES") +}) + test_that("filter_data uses the first module when selection is empty", { testthat::local_mocked_bindings( interactive = function() TRUE, From a09331584d504d092084f7cae853e1b0ae8488c5 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Fri, 27 Nov 2026 11:15:13 -0500 Subject: [PATCH 4/7] tests: fix failing test --- R/convert_output.R | 2 ++ tests/testthat/test-convert_output.R | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/R/convert_output.R b/R/convert_output.R index adfc503d..754726f7 100644 --- a/R/convert_output.R +++ b/R/convert_output.R @@ -254,6 +254,8 @@ convert_output <- function( # }, cli::cli_abort("Unknown file type. Please indicate model.") ) + }else { + model <- models[i] } } else if (is.null(models) || is.na(models[i])) { model <- switch(class(file)[1], diff --git a/tests/testthat/test-convert_output.R b/tests/testthat/test-convert_output.R index 7a17a196..059f6977 100644 --- a/tests/testthat/test-convert_output.R +++ b/tests/testthat/test-convert_output.R @@ -71,7 +71,7 @@ test_that("missing arguments trigger warnings or errors", { models = "fake_model", save_dir = fs::path("fixtures", "ss3_models_converted", "Hake_2018") ), - "`file` not found." + "Output file not compatible." ) dir.create(fs::path("fixtures", "ss3_models_converted", "Hake_2018"), recursive = TRUE) From cb6f5db71e812737388011876a8a86813ff091e7 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Fri, 27 Nov 2026 12:01:44 -0500 Subject: [PATCH 5/7] chore: update WORDLIST --- inst/WORDLIST | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/WORDLIST b/inst/WORDLIST index 4d89ec26..6dee3ae7 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -105,6 +105,7 @@ pkgdown Pre Preformatted preformatted +preselected qq Rceattle rceattle From c4edc0f109becfc88f98507a67300dc80a410024 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 30 Nov 2026 11:10:11 -0500 Subject: [PATCH 6/7] refactor: change "All" to "all" for model selection --- R/plot_abundance_at_age.R | 4 ++-- R/plot_biomass.R | 2 +- R/plot_biomass_at_age.R | 2 +- R/plot_catch_at_age.R | 2 +- R/plot_discard.R | 2 +- R/plot_fishing_mortality.R | 2 +- R/plot_index.R | 2 +- R/plot_landings.R | 2 +- R/plot_natural_mortality.R | 2 +- R/plot_recruitment.R | 2 +- R/plot_recruitment_deviations.R | 2 +- R/plot_selectivity.R | 2 +- R/plot_spawning_biomass.R | 4 ++-- R/plot_spr.R | 2 +- R/plot_stock_recruitment.R | 2 +- R/table_biomass_abundance_catch.R | 2 ++ R/utils_plot.R | 18 +++++++++--------- man/filter_data.Rd | 2 +- man/filter_interactive.Rd | 4 ++-- man/plot_abundance_at_age.Rd | 4 ++-- man/plot_biomass.Rd | 4 ++-- man/plot_biomass_at_age.Rd | 4 ++-- man/plot_catch_at_age.Rd | 4 ++-- man/plot_discard.Rd | 4 ++-- man/plot_fishing_mortality.Rd | 4 ++-- man/plot_index.Rd | 4 ++-- man/plot_landings.Rd | 4 ++-- man/plot_natural_mortality.Rd | 4 ++-- man/plot_recruitment.Rd | 4 ++-- man/plot_recruitment_deviations.Rd | 4 ++-- man/plot_selectivity.Rd | 4 ++-- man/plot_spawning_biomass.Rd | 4 ++-- man/plot_spr.Rd | 4 ++-- man/plot_stock_recruitment.Rd | 4 ++-- man/table_biomass_abundance_catch.Rd | 4 +++- 35 files changed, 64 insertions(+), 60 deletions(-) diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index 322681db..80bcc4d1 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -38,7 +38,7 @@ #' @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: "All" (all models). Set to NULL for interactive selection when available. +#' Default: "all" (all models). Set to NULL for interactive selection when available. #' @param interactive A logical value indicating if the environment is interactive. #' #' Default: `FALSE` @@ -85,7 +85,7 @@ plot_abundance_at_age <- function( scale_amount = 1, proportional = TRUE, module = NULL, - model = "All", + model = "all", interactive = TRUE, make_rda = FALSE, figures_dir = getwd() diff --git a/R/plot_biomass.R b/R/plot_biomass.R index 4488f4c9..6ef3fb16 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -50,7 +50,7 @@ plot_biomass <- function( era = NULL, unit_label = NULL, module = NULL, - model = "All", + model = "all", scale_amount = 1, relative = FALSE, make_rda = FALSE, diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index 4a43f1e7..0a12afb8 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -46,7 +46,7 @@ plot_biomass_at_age <- function( scale_amount = 1, proportional = TRUE, module = NULL, - model = "All", + model = "all", interactive = TRUE, make_rda = FALSE, figures_dir = getwd() diff --git a/R/plot_catch_at_age.R b/R/plot_catch_at_age.R index 72c10b7d..ed08ec3b 100644 --- a/R/plot_catch_at_age.R +++ b/R/plot_catch_at_age.R @@ -74,7 +74,7 @@ plot_catch_at_age <- function( proportional = TRUE, interactive = TRUE, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd() ) { diff --git a/R/plot_discard.R b/R/plot_discard.R index ad7615cc..0dcc475f 100644 --- a/R/plot_discard.R +++ b/R/plot_discard.R @@ -87,7 +87,7 @@ plot_discard <- function( scale_amount = 1, interactive = TRUE, module = NULL, - model = "All", + model = "all", predicted = TRUE, interval = 0.95, tolerance = 0.001, diff --git a/R/plot_fishing_mortality.R b/R/plot_fishing_mortality.R index c10d8f81..729c00a7 100644 --- a/R/plot_fishing_mortality.R +++ b/R/plot_fishing_mortality.R @@ -36,7 +36,7 @@ plot_fishing_mortality <- function( ref_line = "msy", era = NULL, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd(), interactive = TRUE, diff --git a/R/plot_index.R b/R/plot_index.R index 0d70caf6..80fd7a9b 100644 --- a/R/plot_index.R +++ b/R/plot_index.R @@ -75,7 +75,7 @@ plot_index <- function( facet = NULL, interactive = TRUE, module = NULL, - model = "All", + model = "all", focus = NULL, interval = 0.95, log = FALSE, diff --git a/R/plot_landings.R b/R/plot_landings.R index ab830d53..b68c8cb2 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -97,7 +97,7 @@ plot_landings <- function( era = NULL, scale_amount = 1, module = NULL, - model = "All", + model = "all", interactive = TRUE, predicted = TRUE, interval = 0.95, diff --git a/R/plot_natural_mortality.R b/R/plot_natural_mortality.R index 0b00506c..e5cd52c3 100644 --- a/R/plot_natural_mortality.R +++ b/R/plot_natural_mortality.R @@ -26,7 +26,7 @@ plot_natural_mortality <- function( era = NULL, interactive = TRUE, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd(), ... diff --git a/R/plot_recruitment.R b/R/plot_recruitment.R index d68de69a..a4be6280 100644 --- a/R/plot_recruitment.R +++ b/R/plot_recruitment.R @@ -42,7 +42,7 @@ plot_recruitment <- function( # relative = FALSE, interactive = TRUE, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd() ) { diff --git a/R/plot_recruitment_deviations.R b/R/plot_recruitment_deviations.R index 306a8f46..a088546a 100644 --- a/R/plot_recruitment_deviations.R +++ b/R/plot_recruitment_deviations.R @@ -33,7 +33,7 @@ plot_recruitment_deviations <- function( dat, module = NULL, - model = "All", + model = "all", era = NULL, interactive = TRUE, make_rda = FALSE, diff --git a/R/plot_selectivity.R b/R/plot_selectivity.R index 4a75d090..3b7ab268 100644 --- a/R/plot_selectivity.R +++ b/R/plot_selectivity.R @@ -37,7 +37,7 @@ plot_selectivity <- function( facet = NULL, interactive = TRUE, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd(), ... diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index 4fe58dc8..760de602 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -62,7 +62,7 @@ #' @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: "All" (all models). Set to NULL for interactive selection when available. +#' Default: "all" (all models). Set to NULL for interactive selection when available. #' @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 @@ -136,7 +136,7 @@ plot_spawning_biomass <- function( era = NULL, lbs = lifecycle::deprecated(), module = NULL, - model = "All", + model = "all", scale_amount = 1, relative = FALSE, make_rda = FALSE, diff --git a/R/plot_spr.R b/R/plot_spr.R index 188af650..3103f446 100644 --- a/R/plot_spr.R +++ b/R/plot_spr.R @@ -41,7 +41,7 @@ plot_spr <- function( ref_line = "target", era = NULL, module = NULL, - model = "All", + model = "all", interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), diff --git a/R/plot_stock_recruitment.R b/R/plot_stock_recruitment.R index 76074179..0f514b1a 100644 --- a/R/plot_stock_recruitment.R +++ b/R/plot_stock_recruitment.R @@ -43,7 +43,7 @@ plot_stock_recruitment <- function( interactive = TRUE, era = NULL, module = NULL, - model = "All", + model = "all", scale_amount = 1, make_rda = FALSE, figures_dir = getwd() diff --git a/R/table_biomass_abundance_catch.R b/R/table_biomass_abundance_catch.R index 2206935a..bd2456c7 100644 --- a/R/table_biomass_abundance_catch.R +++ b/R/table_biomass_abundance_catch.R @@ -3,6 +3,8 @@ #' @inheritParams plot_recruitment #' @param model Character. Model name found in `dat$model`. If NULL, one model #' is selected interactively when possible, or the first available model is used. +#' Only one model is may be specified at a time. If "all", only the first available +#' model will be selected. #' #' @param biomass_label String. Units for biomass #' diff --git a/R/utils_plot.R b/R/utils_plot.R index dbb87108..89219f00 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -658,7 +658,7 @@ cap_first_letter <- function(s) { #' @inheritParams plot_spawning_biomass #' @param label_name String. Name of the label used to filter #' the data. -#' @param model Character vector. Model names to retain, or "All" to retain +#' @param model Character vector. Model names to retain, or "all" to retain #' all models when multiple models are allowed. If NULL, selection is interactive #' when possible and otherwise defaults to all models when allowed, or the first. #' @@ -1218,10 +1218,10 @@ add_reference_line <- function( #' @param column_name String. Name of the column to allow interactive filtering for. #' #' @param column_value Character vector. Values of the column to filter by. For -#' models, "All" retains all models when multiple selection is allowed. If NULL, +#' models, "all" retains all models when multiple selection is allowed. If NULL, #' selection is interactive when possible, defaulting to all models when multiple #' selection is allowed and the first value otherwise. In the interactive model -#' menu, selecting specific models overrides the preselected "All" option. +#' menu, selecting specific models overrides the preselected "all" option. #' #' Default: NULL #' @@ -1260,23 +1260,23 @@ filter_interactive <- function( if (length(selected) > 1) { available_names <- unique(dat[[column_name]]) if (!is.null(column_value)) { - if ((length(column_value) > 1 || (column_name == "model" && "All" %in% column_value)) && !allow_multiple_selection) { + if ((length(column_value) > 1 || (column_name == "model" && "all" %in% column_value)) && !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] } - selected <- if (default_all && "All" %in% column_value) available_names else column_value + selected <- if (default_all && "all" %in% column_value) available_names else column_value plot_dat <- dat |> dplyr::filter(.data[[column_name]] %in% selected) } else { cli::cli_alert_warning("Multiple {pretty_columns[column_name]}s found in data. \n") options <- as.character(available_names) - if (default_all) options <- c("All", options) + if (default_all) options <- c("all", options) if (interactive()) { if (interactive) { selection <- utils::select.list( options, - preselect = if (default_all) "All" else NULL, + preselect = if (default_all) "all" else NULL, multiple = allow_multiple_selection, title = glue::glue("Select one of the following {pretty_columns[column_name]} names") ) @@ -1286,10 +1286,10 @@ filter_interactive <- function( selection } - selected <- if (default_all && identical(question1, "All")) { + selected <- if (default_all && identical(question1, "all")) { available_names } else if (default_all) { - intersect(available_names, setdiff(question1, "All")) + intersect(available_names, setdiff(question1, "all")) } else { intersect(available_names, question1) } diff --git a/man/filter_data.Rd b/man/filter_data.Rd index 09ea22cc..07e9b1fd 100644 --- a/man/filter_data.Rd +++ b/man/filter_data.Rd @@ -36,7 +36,7 @@ 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. Model names to retain, or "All" to retain +\item{model}{Character vector. Model names to retain, or "all" to retain all models when multiple models are allowed. If NULL, selection is interactive when possible and otherwise defaults to all models when allowed, or the first. diff --git a/man/filter_interactive.Rd b/man/filter_interactive.Rd index c761128e..ac1975bb 100644 --- a/man/filter_interactive.Rd +++ b/man/filter_interactive.Rd @@ -19,10 +19,10 @@ returned from \link[stockplotr]{convert_output}.} \item{column_name}{String. Name of the column to allow interactive filtering for.} \item{column_value}{Character vector. Values of the column to filter by. For -models, "All" retains all models when multiple selection is allowed. If NULL, +models, "all" retains all models when multiple selection is allowed. If NULL, selection is interactive when possible, defaulting to all models when multiple selection is allowed and the first value otherwise. In the interactive model -menu, selecting specific models overrides the preselected "All" option. +menu, selecting specific models overrides the preselected "all" option. Default: NULL} diff --git a/man/plot_abundance_at_age.Rd b/man/plot_abundance_at_age.Rd index 693d5adc..cfa59f05 100644 --- a/man/plot_abundance_at_age.Rd +++ b/man/plot_abundance_at_age.Rd @@ -11,7 +11,7 @@ plot_abundance_at_age( scale_amount = 1, proportional = TRUE, module = NULL, - model = "All", + model = "all", interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -58,7 +58,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \item{interactive}{A logical value indicating if the environment is interactive. diff --git a/man/plot_biomass.Rd b/man/plot_biomass.Rd index 9231256c..764bebe1 100644 --- a/man/plot_biomass.Rd +++ b/man/plot_biomass.Rd @@ -13,7 +13,7 @@ plot_biomass( era = NULL, unit_label = NULL, module = NULL, - model = "All", + model = "all", scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -79,7 +79,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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 diff --git a/man/plot_biomass_at_age.Rd b/man/plot_biomass_at_age.Rd index 1b4ef4d6..d2f22b1f 100644 --- a/man/plot_biomass_at_age.Rd +++ b/man/plot_biomass_at_age.Rd @@ -11,7 +11,7 @@ plot_biomass_at_age( scale_amount = 1, proportional = TRUE, module = NULL, - model = "All", + model = "all", interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -56,7 +56,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment in which the function is operating is interactive. This bypasses some options for diff --git a/man/plot_catch_at_age.Rd b/man/plot_catch_at_age.Rd index 784e4bc2..c5932c6b 100644 --- a/man/plot_catch_at_age.Rd +++ b/man/plot_catch_at_age.Rd @@ -13,7 +13,7 @@ plot_catch_at_age( proportional = TRUE, interactive = TRUE, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd() ) @@ -69,7 +69,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_discard.Rd b/man/plot_discard.Rd index 1b951610..7a07ea8d 100644 --- a/man/plot_discard.Rd +++ b/man/plot_discard.Rd @@ -15,7 +15,7 @@ plot_discard( scale_amount = 1, interactive = TRUE, module = NULL, - model = "All", + model = "all", predicted = TRUE, interval = 0.95, tolerance = 0.001, @@ -92,7 +92,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \item{predicted}{Logical. TRUE (Default) or FALSE; show the discards predicted by the model as lines, with the observed discards as points, to diff --git a/man/plot_fishing_mortality.Rd b/man/plot_fishing_mortality.Rd index 89f60a06..02bbbc33 100644 --- a/man/plot_fishing_mortality.Rd +++ b/man/plot_fishing_mortality.Rd @@ -12,7 +12,7 @@ plot_fishing_mortality( ref_line = "msy", era = NULL, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd(), interactive = TRUE, @@ -75,7 +75,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_index.Rd b/man/plot_index.Rd index f68e7a8d..8ec62b5a 100644 --- a/man/plot_index.Rd +++ b/man/plot_index.Rd @@ -11,7 +11,7 @@ plot_index( facet = NULL, interactive = TRUE, module = NULL, - model = "All", + model = "all", focus = NULL, interval = 0.95, log = FALSE, @@ -56,7 +56,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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 a8995661..02c84ff5 100644 --- a/man/plot_landings.Rd +++ b/man/plot_landings.Rd @@ -14,7 +14,7 @@ plot_landings( era = NULL, scale_amount = 1, module = NULL, - model = "All", + model = "all", interactive = TRUE, predicted = TRUE, interval = 0.95, @@ -88,7 +88,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. diff --git a/man/plot_natural_mortality.Rd b/man/plot_natural_mortality.Rd index 6e1795ba..21e957fa 100644 --- a/man/plot_natural_mortality.Rd +++ b/man/plot_natural_mortality.Rd @@ -11,7 +11,7 @@ plot_natural_mortality( era = NULL, interactive = TRUE, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd(), ... @@ -56,7 +56,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_recruitment.Rd b/man/plot_recruitment.Rd index c71cf597..7d55d64d 100644 --- a/man/plot_recruitment.Rd +++ b/man/plot_recruitment.Rd @@ -13,7 +13,7 @@ plot_recruitment( facet = NULL, interactive = TRUE, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd() ) @@ -68,7 +68,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_recruitment_deviations.Rd b/man/plot_recruitment_deviations.Rd index a187217c..12973e3d 100644 --- a/man/plot_recruitment_deviations.Rd +++ b/man/plot_recruitment_deviations.Rd @@ -7,7 +7,7 @@ plot_recruitment_deviations( dat, module = NULL, - model = "All", + model = "all", era = NULL, interactive = TRUE, make_rda = FALSE, @@ -33,7 +33,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \item{era}{String. Era of data. diff --git a/man/plot_selectivity.Rd b/man/plot_selectivity.Rd index de8af024..92dcbc9d 100644 --- a/man/plot_selectivity.Rd +++ b/man/plot_selectivity.Rd @@ -11,7 +11,7 @@ plot_selectivity( facet = NULL, interactive = TRUE, module = NULL, - model = "All", + model = "all", make_rda = FALSE, figures_dir = getwd(), ... @@ -54,7 +54,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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, diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index 18ec4610..a102239f 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -14,7 +14,7 @@ plot_spawning_biomass( era = NULL, lbs = lifecycle::deprecated(), module = NULL, - model = "All", + model = "all", scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -93,7 +93,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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 diff --git a/man/plot_spr.Rd b/man/plot_spr.Rd index a9cde6d3..c094e05b 100644 --- a/man/plot_spr.Rd +++ b/man/plot_spr.Rd @@ -12,7 +12,7 @@ plot_spr( ref_line = "target", era = NULL, module = NULL, - model = "All", + model = "all", interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), @@ -76,7 +76,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. diff --git a/man/plot_stock_recruitment.Rd b/man/plot_stock_recruitment.Rd index 47ae2d66..697b5898 100644 --- a/man/plot_stock_recruitment.Rd +++ b/man/plot_stock_recruitment.Rd @@ -11,7 +11,7 @@ plot_stock_recruitment( interactive = TRUE, era = NULL, module = NULL, - model = "All", + model = "all", scale_amount = 1, make_rda = FALSE, figures_dir = getwd() @@ -56,7 +56,7 @@ 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: "All" (all models). Set to NULL for interactive selection when available.} +Default: "all" (all models). Set to NULL for interactive selection when available.} \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 diff --git a/man/table_biomass_abundance_catch.Rd b/man/table_biomass_abundance_catch.Rd index fc857486..a2ee5848 100644 --- a/man/table_biomass_abundance_catch.Rd +++ b/man/table_biomass_abundance_catch.Rd @@ -79,7 +79,9 @@ in this ordered list: "landings_weight", "landings_numbers", "landings_expected Default: NULL} \item{model}{Character. Model name found in \code{dat$model}. If NULL, one model -is selected interactively when possible, or the first available model is used.} +is selected interactively when possible, or the first available model is used. +Only one model is may be specified at a time. If "all", only the first available +model will be selected.} \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, From 224fca852740e4086b016978cd6df05cdf841c10 Mon Sep 17 00:00:00 2001 From: Joshua Zahner Date: Mon, 30 Nov 2026 11:10:28 -0500 Subject: [PATCH 7/7] chore: update tests --- R/convert_output.R | 2 +- tests/testthat/test-plot_spawning_biomass.R | 2 +- tests/testthat/test-utils_plot.R | 27 ++++++++++++--------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/R/convert_output.R b/R/convert_output.R index 754726f7..65eab2a7 100644 --- a/R/convert_output.R +++ b/R/convert_output.R @@ -254,7 +254,7 @@ convert_output <- function( # }, cli::cli_abort("Unknown file type. Please indicate model.") ) - }else { + } else { model <- models[i] } } else if (is.null(models) || is.na(models[i])) { diff --git a/tests/testthat/test-plot_spawning_biomass.R b/tests/testthat/test-plot_spawning_biomass.R index 8f246963..8b6fde48 100644 --- a/tests/testthat/test-plot_spawning_biomass.R +++ b/tests/testthat/test-plot_spawning_biomass.R @@ -67,7 +67,7 @@ test_that("plot_spawning_biomass plots all models by default", { test_that("interactive model selection limits the plot", { testthat::local_mocked_bindings(interactive = function() TRUE, .package = "base") testthat::local_mocked_bindings( - select.list = function(...) c("All", "model2"), + select.list = function(...) c("all", "model2"), .package = "utils" ) dat <- dplyr::bind_rows( diff --git a/tests/testthat/test-utils_plot.R b/tests/testthat/test-utils_plot.R index 8f5d5ada..c84fcc3c 100644 --- a/tests/testthat/test-utils_plot.R +++ b/tests/testthat/test-utils_plot.R @@ -95,10 +95,10 @@ test_that("model defaults retain all models in interactive and non-interactive m expect_setequal(unique(filtered$group_var), c("model_one", "model_two")) expect_setequal(get("selected_model", envir = .GlobalEnv), c("model_one", "model_two")) } - expect_equal(choices_seen, c("All", "model_one", "model_two")) - expect_equal(preselect_seen, "All") + expect_equal(choices_seen, c("all", "model_one", "model_two")) + expect_equal(preselect_seen, "all") - selection <- "All" + selection <- "all" filtered <- filter_data( dat = dat, label_name = "^biomass$", geom = "line", interactive = TRUE ) @@ -110,7 +110,7 @@ test_that("model defaults retain all models in interactive and non-interactive m ) expect_equal(unique(filtered$model), "model_two") - selection <- c("All", "model_two") + selection <- c("all", "model_two") filtered <- filter_data( dat = dat, label_name = "^biomass$", geom = "line", interactive = TRUE ) @@ -124,10 +124,10 @@ test_that("model defaults retain all models in interactive and non-interactive m expect_equal(unique(filtered$model), "model_two") }) -test_that("specific interactive model selections override All", { +test_that("specific interactive model selections override all", { testthat::local_mocked_bindings(interactive = function() TRUE, .package = "base") testthat::local_mocked_bindings( - select.list = function(...) c("All", "model_two", "model_three"), + select.list = function(...) c("all", "model_two", "model_three"), .package = "utils" ) dat <- tibble::tibble(model = c("model_one", "model_two", "model_three", "model_four")) @@ -147,16 +147,21 @@ test_that("model defaults retain all models when the environment is non-interact } }) -test_that("All selects every model but remains a literal module name", { +test_that("all selects every model but remains a literal module name", { dat <- make_utils_plot_multimodel_data() - selected <- stockplotr:::filter_interactive(dat, "model", column_value = "All") + selected <- stockplotr:::filter_interactive(dat, "model", column_value = "all") expect_identical(selected$plot_data, dat) expect_equal(selected$selected, c("model_one", "model_two")) - modules <- tibble::tibble(module_name = c("All", "OTHER")) - selected <- stockplotr:::filter_interactive(modules, "module_name", column_value = "All") - expect_equal(selected$plot_data$module_name, "All") + models <- tibble::tibble(model = c("All", "OTHER")) + selected <- stockplotr:::filter_interactive(models, "model", column_value = "All") + expect_equal(selected$plot_data$model, "All") expect_equal(selected$selected, "All") + + modules <- tibble::tibble(module_name = c("all", "All", "OTHER")) + selected <- stockplotr:::filter_interactive(modules, "module_name", column_value = "all") + expect_equal(selected$plot_data$module_name, "all") + expect_equal(selected$selected, "all") }) test_that("single-model selection and module selection retain their defaults", {