Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions R/convert_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
7 changes: 2 additions & 5 deletions R/plot_abundance_at_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion R/plot_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/plot_biomass_at_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion R/plot_catch_at_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
) {
Expand Down
2 changes: 1 addition & 1 deletion R/plot_discard.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/plot_fishing_mortality.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/plot_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ plot_index <- function(
facet = NULL,
interactive = TRUE,
module = NULL,
model = NULL,
model = "All",
focus = NULL,
interval = 0.95,
log = FALSE,
Expand Down
2 changes: 1 addition & 1 deletion R/plot_landings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/plot_natural_mortality.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ plot_natural_mortality <- function(
era = NULL,
interactive = TRUE,
module = NULL,
model = NULL,
model = "All",
make_rda = FALSE,
figures_dir = getwd(),
...
Expand Down
2 changes: 1 addition & 1 deletion R/plot_recruitment.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ plot_recruitment <- function(
# relative = FALSE,
interactive = TRUE,
module = NULL,
model = NULL,
model = "All",
make_rda = FALSE,
figures_dir = getwd()
) {
Expand Down
2 changes: 1 addition & 1 deletion R/plot_recruitment_deviations.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
plot_recruitment_deviations <- function(
dat,
module = NULL,
model = NULL,
model = "All",
era = NULL,
interactive = TRUE,
make_rda = FALSE,
Expand Down
2 changes: 1 addition & 1 deletion R/plot_selectivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ plot_selectivity <- function(
facet = NULL,
interactive = TRUE,
module = NULL,
model = NULL,
model = "All",
make_rda = FALSE,
figures_dir = getwd(),
...
Expand Down
7 changes: 2 additions & 5 deletions R/plot_spawning_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/plot_spr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 3 additions & 2 deletions R/plot_stock_recruitment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions R/process_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions R/table_biomass_abundance_catch.R
Original file line number Diff line number Diff line change
@@ -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
#'
Expand Down
2 changes: 2 additions & 0 deletions R/table_index.R
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions R/table_landings.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions R/table_total_catch.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
57 changes: 34 additions & 23 deletions R/utils_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,14 @@ 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.
#'
#' Default: TRUE
#'
Expand Down Expand Up @@ -690,7 +697,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",
Expand Down Expand Up @@ -1210,8 +1217,11 @@ 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. 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
#'
Expand All @@ -1221,7 +1231,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`).
#'
Expand All @@ -1243,55 +1253,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 |>
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pkgdown
Pre
Preformatted
preformatted
preselected
qq
Rceattle
rceattle
Expand Down
12 changes: 6 additions & 6 deletions man/filter_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading