Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8781e4e
Update indices table as per https://github.com/nmfs-ost/stockplotr/is…
sbreitbart-NOAA Jun 2, 2026
04f1b2a
Add commas to large numbers in tables
sbreitbart-NOAA Jun 3, 2026
923577b
update converter indices names for BAM
Schiano-NOAA Jun 4, 2026
7ed50d5
fix bam naming conventions from expected to observed
Schiano-NOAA Jun 4, 2026
19823d1
convert "indices" to "index"
sbreitbart-NOAA Jun 4, 2026
c056c30
update gitignore and Rbuildignore
sbreitbart-NOAA Jun 5, 2026
f219216
Revert "convert "indices" to "index""
sbreitbart-NOAA Jun 5, 2026
e7e059a
change selected names to index from indices, maintaining native names…
Schiano-NOAA Jun 5, 2026
1ae65a7
rename "indices" to "index" throughout package (except for converter)
sbreitbart-NOAA Jun 5, 2026
626b3ff
add correct names mutate to Rceattle index labels
Schiano-NOAA Jun 8, 2026
60293a8
fix issue with Rceattle incompatability in table_index
Schiano-NOAA Jun 8, 2026
e10cf0d
add table_index() to save_all_plots() function and test
sbreitbart-NOAA Jun 10, 2026
b95e2ea
add condition so if uncertainty is missing it gets filled in
Schiano-NOAA Jun 10, 2026
28d4646
Fix group bug (#279)
Schiano-NOAA Jun 10, 2026
70c3647
add conditional when numbers and weight are both present
Schiano-NOAA Jun 10, 2026
ba09a36
remove duplicated names from BAM conout sheet
Schiano-NOAA Jun 12, 2026
5fa035b
add notes and adjustment to merge_error to fix issue with creating ta…
Schiano-NOAA Jun 12, 2026
1cd93aa
add grouping variables if they occur
Schiano-NOAA Jun 12, 2026
b84b328
comment out groupings in column names
Schiano-NOAA Jun 12, 2026
8ad4363
add paranethese around unit label if present
Schiano-NOAA Jun 17, 2026
bdd6e07
add conditions for other groupings and adjust labels; not working for…
Schiano-NOAA Jun 17, 2026
d33bdef
restart function to combine error with value in columns for tables
Schiano-NOAA Jun 24, 2026
f7539ec
replace merge_error with more efficient and simple function
Schiano-NOAA Jun 25, 2026
ddd7c19
finish adjustment for merge_error and add correct order of arguments …
Schiano-NOAA Jun 25, 2026
199c572
make small change to final header name and reflect changes to merge_e…
Schiano-NOAA Jun 25, 2026
d8acba1
update documentation and fix plot_index test
Schiano-NOAA Jun 25, 2026
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 .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^\.positai$
^\.claude$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ docs
stockplotr.Rproj
*.Rproj
!vignettes/figures/
.positai
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export(plot_biomass)
export(plot_biomass_at_age)
export(plot_catch_comp)
export(plot_fishing_mortality)
export(plot_indices)
export(plot_index)
export(plot_landings)
export(plot_natural_mortality)
export(plot_obsvpred)
Expand All @@ -27,5 +27,6 @@ export(process_data)
export(process_table)
export(reference_line)
export(save_all_plots)
export(table_index)
export(table_landings)
export(theme_noaa)
14 changes: 10 additions & 4 deletions R/convert_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ convert_output <- function(
uncertainty = log_sd
) |>
dplyr::mutate(
# label = "indices_observed",
# label = "index_observed",
uncertainty_label = "log_sd",
indices_predicted = dat$quantities$index_hat
) |>
Expand All @@ -1956,12 +1956,13 @@ convert_output <- function(
values_to = "estimate"
) |>
dplyr::mutate(
module_name = names(extract) # ,
module_name = names(extract),
# era = dplyr::if_else(
# year > dat$data_list$endyr,
# "fore",
# NA_character_
# )
label = stringr::str_replace_all(label, "indices", "index")
)

df_index_long[setdiff(tolower(names(out_new)), tolower(names(df_index_long)))] <- NA
Expand Down Expand Up @@ -2013,7 +2014,7 @@ convert_output <- function(
df_comp_obs <- dat$data_list$comp_data |>
dplyr::rename_with(tolower) |>
dplyr::mutate(
label = "indices_observed"
label = "index_observed"
)

indexing_vars_cols <- colnames(df_comp_obs)[!grepl("comp", colnames(df_comp_obs))]
Expand Down Expand Up @@ -2185,10 +2186,15 @@ convert_output <- function(
# }

# edit: here is a different way of loading in the csv sheets
con_file <- system.file("resources", glue::glue("{model}_var_names.csv"), package = "stockplotr", mustWork = TRUE)
con_file <- system.file("resources", glue::glue("{tolower(model)}_var_names.csv"), package = "stockplotr", mustWork = TRUE)
# temporarily add call to local csv so I can test
# con_file <- glue::glue("~/GitHub/stockplotr/inst/resources/{model}_var_names.csv")
var_names_sheet <- utils::read.csv(con_file, na.strings = "")

if (tolower(model) == "bam") {
var_names_sheet <- var_names_sheet |>
dplyr::mutate(label = tolower(label))
}

if (file.exists(con_file)) {
# Remove 'X' column if it exists
Expand Down
12 changes: 6 additions & 6 deletions R/plot_indices.R → R/plot_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' filtered. (i.e. select names of fleets to zoom into the plot)
#'
#' Default: NULL
#' @returns A plot showing the expected and predicted indices.
#' @returns A plot showing the expected and predicted index.
#'
#' @details The input is from an assessment model output file
#' translated to a standardized output (\link[stockplotr]{convert_output}).
Expand All @@ -25,13 +25,13 @@
#' @export
#'
#' @examples
#' plot_indices(
#' plot_index(
#' dat = stockplotr:::example_data,
#' unit_label = "fish/hr",
#' interactive = FALSE
#' )
#'
plot_indices <- function(
plot_index <- function(
dat,
unit_label = "",
group = NULL,
Expand All @@ -57,7 +57,7 @@ plot_indices <- function(
# Filter data
prepared_data <- filter_data(
dat,
label_name = "indices",
label_name = "index",
era = NULL,
geom = "line",
# ifelse guarantees the code doesn't miss grouping when label has > 1 value
Expand Down Expand Up @@ -98,8 +98,8 @@ plot_indices <- function(
dat = prepared_data,
x = "year",
y = "estimate",
observed_label = "indices_observed",
predicted_label = "indices_predicted",
observed_label = "index_observed",
predicted_label = "index_predicted",
geom = "line",
xlab = "Year",
ylab = "Estimated Index",
Expand Down
4 changes: 2 additions & 2 deletions R/process_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ process_table <- function(
dplyr::rename(
!!mod_uncert_lab := uncertainty
) |>
# set values to strings to include training zeros from rounding
dplyr::mutate(estimate = sprintf(glue::glue("%.{digits}f"), estimate)) |>
# set values to strings to include trailing zeros from rounding and # format large estimate values with commas
dplyr::mutate(estimate = formatC(estimate, format = "f", digits = digits, big.mark = ",")) |>
tidyr::pivot_wider(
id_cols = dplyr::all_of(c(stringr::str_to_title(mod_cols))),
values_from = dplyr::all_of(c("estimate", mod_uncert_lab)),
Expand Down
55 changes: 28 additions & 27 deletions R/save_all_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
#'
#' Default: "mt"
#'
#' @param indices_unit_label Units for index of abundance/CPUE
#' @param index_unit_label Units for index of abundance/CPUE
#'
#' Default: ""
#'
Expand Down Expand Up @@ -119,7 +119,7 @@
#' save_all_plots(dat,
#' ref_line = "unfished",
#' ref_line_sb = "target",
#' indices_unit_label = "CPUE",
#' index_unit_label = "CPUE",
#' biomass_at_age_scale_amount = 1,
#' biomass_at_age_unit_label = "metric tons"
#' )
Expand Down Expand Up @@ -150,15 +150,15 @@ save_all_plots <- function(
# imported from plot_biomass_at_age
biomass_at_age_scale_amount = 1,
biomass_at_age_unit_label = "mt",
# imported from plot_indices
indices_unit_label = "",
# imported from plot_index
index_unit_label = "",
# imported from table_afsc_tier- add potential unique arguments after dev
# imported from table_bnc
biomass_unit_label = "mt",
catch_unit_label = "mt",
catch_scale_amount = 1
# imported from table_harvest_projection- add potential unique arguments after dev
# imported from table_indices- zero unique arguments
# imported from table_index- zero unique arguments
# imported from table_landings- zero unique arguments
) {
make_rda <- TRUE
Expand Down Expand Up @@ -419,18 +419,18 @@ save_all_plots <- function(

tryCatch(
{
cli::cli_h2("plot_indices")
plot_indices(dat,
unit_label = indices_unit_label,
cli::cli_h2("plot_index")
plot_index(dat,
unit_label = index_unit_label,
make_rda = TRUE,
interactive = FALSE,
figures_dir = figures_tables_dir
) # |> suppressWarnings() |> invisible()
},
error = function(e) {
cli::cli_alert_danger("plot_indices failed to run.")
cli::cli_alert_danger("plot_index failed to run.")
cli::cli_alert("Tip: check that your arguments are correct.")
cli::cli_li("indices_unit_label = {indices_unit_label}")
cli::cli_li("index_unit_label = {index_unit_label}")
print(e)
}
)
Expand Down Expand Up @@ -460,23 +460,24 @@ save_all_plots <- function(
# }
# )

# tryCatch(
# {
# cli::cli_h2("table_indices")
# table_indices(
# dat,
# make_rda = TRUE,
# tables_dir = figures_tables_dir
# ) # |>
# # suppressWarnings() |>
# # invisible()
# },
# error = function(e) {
# cli::cli_alert_danger("table_indices failed to run.")
# cli::cli_alert("Tip: check that your arguments are correct.")
# print(e)
# }
# )
tryCatch(
{
cli::cli_h2("table_index")
table_index(
dat,
interactive = FALSE,
make_rda = TRUE,
tables_dir = figures_tables_dir
) # |>
# suppressWarnings() |>
# invisible()
},
error = function(e) {
cli::cli_alert_danger("table_index failed to run.")
cli::cli_alert("Tip: check that your arguments are correct.")
print(e)
}
)

tryCatch(
{
Expand Down
2 changes: 1 addition & 1 deletion R/table_afsc_tier.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ table_afsc_tier <- function() {
# -adds make_rda and tables_dir as arguments
# -defines topic_label, fig_or_table; and
# -makes an rda if make_rda = TRUE
# (see table_indices.R for reference)
# (see table_index.R for reference)
# for the rda-related fxns to work, the final table has to be called tab

# identify output
Expand Down
2 changes: 1 addition & 1 deletion R/table_harvest_projection.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ table_harvest_projection <- function() {
# -adds make_rda and tables_dir as arguments
# -defines topic_label, fig_or_table; and
# -makes an rda if make_rda = TRUE
# (see table_indices.R for reference)
# (see table_index.R for reference)
# for the rda-related fxns to work, the final table has to be called tab

level <- c(
Expand Down
Loading
Loading