diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index d4631943..9828ad79 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -113,7 +113,8 @@ plot_abundance_at_age <- function( if (make_rda == TRUE) { create_rda( object = plot, - topic_label = "pop.naa", + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat, unit_label = "mt" diff --git a/R/plot_biomass.R b/R/plot_biomass.R index c75f6798..944c5ac1 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -151,7 +151,7 @@ plot_biomass <- function( if (make_rda) { create_rda( object = final, - topic_label = ifelse(relative, "relative.biomass", "biomass"), + topic_label = ifelse(relative, "relative_biomass", "biomass"), fig_or_table = "figure", dat = rp_dat, dir = figures_dir, diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index 1c3f671d..a2417982 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -97,7 +97,8 @@ plot_biomass_at_age <- function( if (make_rda == TRUE) { create_rda( object = plot, - topic_label = "pop.baa", + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat, unit_label = "mt" diff --git a/R/plot_catch_comp.R b/R/plot_catch_comp.R index 675b1463..4fc178ae 100644 --- a/R/plot_catch_comp.R +++ b/R/plot_catch_comp.R @@ -113,7 +113,8 @@ plot_catch_comp <- function( if (make_rda == TRUE) { create_rda( object = plot, - topic_label = "pop.caa", + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat, unit_label = "mt" diff --git a/R/plot_fishing_mortality.R b/R/plot_fishing_mortality.R index 7d967944..d34d8ca5 100644 --- a/R/plot_fishing_mortality.R +++ b/R/plot_fishing_mortality.R @@ -97,7 +97,7 @@ plot_fishing_mortality <- function( if (make_rda) { create_rda( object = final, - topic_label = ifelse(relative, "relative.fishing.mortality", "fishing.mortality"), + topic_label = ifelse(relative, "relative_fishing_mortality", "fishing_mortality"), fig_or_table = "figure", dat = dat, dir = figures_dir, diff --git a/R/plot_indices.R b/R/plot_indices.R index c9384619..2f2040d4 100644 --- a/R/plot_indices.R +++ b/R/plot_indices.R @@ -116,7 +116,8 @@ plot_indices <- function( if (make_rda) { create_rda( object = plt, - topic_label = "CPUE.indices", + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir, diff --git a/R/plot_landings.R b/R/plot_landings.R index 00680212..04dec696 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -101,7 +101,8 @@ plot_landings <- function( if (make_rda) { create_rda( object = plt, - topic_label = "landings", + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir, diff --git a/R/plot_natural_mortality.R b/R/plot_natural_mortality.R index 17ee74b2..25d5bf5d 100644 --- a/R/plot_natural_mortality.R +++ b/R/plot_natural_mortality.R @@ -104,7 +104,8 @@ plot_natural_mortality <- function( if (make_rda) { create_rda( object = final, - topic_label = "natural.mortality", + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir diff --git a/R/plot_recruitment.R b/R/plot_recruitment.R index 24c4715f..a6de07de 100644 --- a/R/plot_recruitment.R +++ b/R/plot_recruitment.R @@ -146,7 +146,8 @@ plot_recruitment <- function( if (make_rda) { create_rda( object = final, - topic_label = caption_label, + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir # , diff --git a/R/plot_recruitment_deviations.R b/R/plot_recruitment_deviations.R index e7e3744c..acaf86ac 100644 --- a/R/plot_recruitment_deviations.R +++ b/R/plot_recruitment_deviations.R @@ -102,7 +102,8 @@ plot_recruitment_deviations <- function( } create_rda( object = final, - topic_label = "recruitment.deviations", + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = selected_dat, dir = figures_dir, diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index 4fd29179..7d23612d 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -207,7 +207,7 @@ plot_spawning_biomass <- function( if (make_rda) { create_rda( object = final, - topic_label = ifelse(relative, "relative.spawning.biomass", "spawning.biomass"), + topic_label = ifelse(relative, "relative_spawning_biomass", "spawning_biomass"), fig_or_table = "figure", dat = rp_dat, dir = figures_dir, diff --git a/R/plot_stock_recruitment.R b/R/plot_stock_recruitment.R index 086f5406..8a9ea0b7 100644 --- a/R/plot_stock_recruitment.R +++ b/R/plot_stock_recruitment.R @@ -129,7 +129,8 @@ plot_stock_recruitment <- function( if (make_rda) { create_rda( object = final, - topic_label = "sr", + # get name of function and remove "plot_" from it + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir # , diff --git a/R/table_bnc.R b/R/table_bnc.R index 535eb555..0881d1a7 100644 --- a/R/table_bnc.R +++ b/R/table_bnc.R @@ -179,12 +179,13 @@ # fig_or_table = fig_or_table, # dir = tables_dir # ) - +# # export_rda( # object = final, # caps_alttext = caps_alttext, # figures_tables_dir = tables_dir, -# topic_label = topic_label, +# # get name of function and remove "table_" from it +# topic_label = gsub("table_", "", as.character(sys.call()[[1]])), # fig_or_table = fig_or_table # ) # } diff --git a/R/table_indices.R b/R/table_indices.R index 7faa1d4e..fe2d58c7 100644 --- a/R/table_indices.R +++ b/R/table_indices.R @@ -155,13 +155,14 @@ # ) -# export_rda( -# object = final, -# caps_alttext = caps_alttext, -# figures_tables_dir = tables_dir, -# topic_label = topic_label, -# fig_or_table = fig_or_table -# ) + # export_rda( + # object = final, + # caps_alttext = caps_alttext, + # figures_tables_dir = tables_dir, + # # get name of function and remove "table_" from it + # topic_label = gsub("table_", "", as.character(sys.call()[[1]])), + # fig_or_table = fig_or_table + # ) # } # final # } diff --git a/R/table_landings.R b/R/table_landings.R index 2d6a3bf6..0438227e 100644 --- a/R/table_landings.R +++ b/R/table_landings.R @@ -114,7 +114,8 @@ table_landings <- function( if (length(df_list) == 1) { create_rda( object = final$label, - topic_label = "landings", + # get name of function and remove "table_" from it + topic_label = gsub("table_", "", as.character(sys.call()[[1]])), fig_or_table = "table", dat = dat, dir = tables_dir, diff --git a/R/utils_rda.R b/R/utils_rda.R index 4927207d..dadddb23 100644 --- a/R/utils_rda.R +++ b/R/utils_rda.R @@ -151,7 +151,7 @@ add_more_key_quants <- function( # calculate key quantities that rely on end_year for calculation ## terminal fishing mortality - # if (topic_cap_alt$label == "fishing.mortality") { + # if (topic_cap_alt$label == "fishing_mortality") { # if (is.null(dat)) { # cli::cli_alert_warning("Some key quantities associated with fishing mortality were not extracted and added to captions_alt_text.csv due to missing data file (i.e., 'dat' argument).", wrap = TRUE) # } else { @@ -195,6 +195,10 @@ add_more_key_quants <- function( # write analogous code for each in this section, and remove placeholders from # the end of write_captions (once we get clarity about how to extract Btarg, # ssbtarg, and R0) + # + + #TODO: When adding code extracting values for landings and/or indices figures/tables, be aware that both figure/table share the same label ("landings" and "indices"). If there's reason, add in extra conditional to check if value is from a figure or table + ## biomass if (topic_cap_alt$label == "biomass") { if (is.null(dat)) { @@ -247,7 +251,7 @@ add_more_key_quants <- function( } ## relative spawning biomass - if (topic_cap_alt$label == "relative.spawning.biomass") { + if (topic_cap_alt$label == "relative_spawning_biomass") { if (is.null(dat)) { cli::cli_alert_warning("Some key quantities associated with relative spawning biomass were not extracted and added to captions_alt_text.csv due to missing data file (i.e., 'dat' argument).", wrap = TRUE) } @@ -318,7 +322,7 @@ add_more_key_quants <- function( } ## spawning biomass - if (topic_cap_alt$label == "spawning.biomass" | topic_cap_alt$label == "sr") { + if (topic_cap_alt$label == "spawning_biomass" | topic_cap_alt$label == "stock_recruitment") { if (is.null(dat)) { cli::cli_alert_warning("Some key quantities associated with spawning biomass were not extracted and added to captions_alt_text.csv due to missing data file (i.e., 'dat' argument).", wrap = TRUE) } else { @@ -423,7 +427,7 @@ add_more_key_quants <- function( } ## recruitment - if (topic_cap_alt$label == "recruitment" | topic_cap_alt$label == "sr") { + if (topic_cap_alt$label == "recruitment" | topic_cap_alt$label == "stock_recruitment") { if (is.null(dat)) { cli::cli_alert_warning("Some key quantities associated with recruitment were not extracted and added to captions_alt_text.csv due to missing data file (i.e., 'dat' argument).", wrap = TRUE) } else { diff --git a/R/write_captions.R b/R/write_captions.R deleted file mode 100644 index 2f21b31f..00000000 --- a/R/write_captions.R +++ /dev/null @@ -1,1102 +0,0 @@ -#' Write captions and alternative text -#' -#' Function to create captions and alternative text that contain -#' key quantities from the model results file. -#' -#' @inheritParams plot_spawning_biomass -#' @param dir Directory where the output captions and alt text file should be -#' saved. Defaults to working directory. -#' @param year the last year of the data or the current year this function is -#' being performed. Defaults to the current year. -#' -#' @return Exports .csv with captions and alt text for figures and tables -#' that contain key quantities (e.g., an assessment's start year) that -#' are automatically extracted from the converted model results file. -#' -#' @export -#' -#' @examples -#' \dontrun{ -#' write_captions(dat, -#' dir = getwd(), -#' year = 2025 -#' ) -#' } -write_captions <- function(dat, # converted model output object - dir = getwd(), - year = format(Sys.Date(), "%Y")) { - # only extract key quantities/export new csv if not present - if (file.exists(fs::path(dir, "captions_alt_text.csv"))) { - cli::cli_alert_danger("Captions and alternative text file (captions_alt_text.csv) already exists; write_captions() will not run.", wrap = TRUE) - cli::cli_alert_info("To extract new key quantities and make a new captions_alt_text.csv file, delete existing captions_alt_text.csv and rerun write_captions().", wrap = TRUE) - } else { - # import pre-written captions and alt text that include placeholders - # for key quantities (e.g., 'start_year' is the placeholder for the - # assessment's start year) - caps_alttext <- utils::read.csv( - system.file("resources", "captions_alt_text_template.csv", package = "stockplotr") - ) - - dat <- dat |> - dplyr::mutate( - estimate = as.numeric(estimate), - year = as.numeric(year), - age = as.numeric(age) - ) - - # extract key quantities - # REMINDERS: - # -the variable names must exactly match those in the captions/alt text csv. - - # suppress warnings - options(warn = -1) - - # FIGURES----- - - ## kobe plot- don't code quantities yet - # kobe.end.year <- - # value of B/B(MSY) at the end year - # B.BMSY.end.yr <- B/BMSY - # --B = time series of biomass, last year - # --BMSY = dplyr::filter(grepl('b_target', label) | grepl('b_msy', label) | c(grepl('fishing_mortality_msy', label) & is.na(year))) - # CHECK: if length > 1, then select b_target - - # value of F/F(MSY) at the end year - # F.FMSY.end.yr <- - - # object that should be "is" or "is not" and answers the question, - # "the stock overfishing status ... overfished" - # overfished.status.is.isnot <- - - # object that should be "is" or "is not" and answers the question, - # "the stock ... experiencing overfishing" - # overfishing.status.is.isnot <- - - - ## Biomass plot - # biomass reference point - # B.ref.pt : added with add_more_key_quants - - # start year of biomass plot - B.start.year <- dat |> - dplyr::filter( - label == "biomass", - module_name == "TIME_SERIES" | module_name == "t.series", # SS3 and BAM target module names - is.na(fleet), - is.na(age) - ) |> - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() - - # end year of biomass plot - # B.end.year : added with add_more_key_quants - - # units of B (plural) - # B.units : added with add_more_key_quants - - # minimum B : added with add_more_key_quants - - # maximum B : added with add_more_key_quants - - - # TODO: uncomment and recode once we get clarity about how to extract this value properly - # R0 - # R0 <- dat |> - # dplyr::filter( - # # pull from BAM - # grepl('^recruitment$', label) & module_name == "parms" | - # grepl('^R0', label) | - # # pull from SS3 - # grepl('recruitment_virgin', label) - # ) |> - # dplyr::pull(estimate) |> - # unique() |> - # as.numeric() |> - # round(digits = 2) - - # Bend <- - - # TODO: uncomment and recode once we get clarity about how to extract this value properly - # Target biomass - # Btarg <- dat |> - # dplyr::filter(c(grepl('biomass', label) & grepl('target', label) & estimate >1) | label == 'biomass_msy') |> - # dplyr::pull(estimate) |> - # as.numeric() |> - # round(digits = 2) - - # Bmsy <- - - - # TODO: uncomment and recode once we get clarity about how to extract Btarg properly - ## relative B - # relative B min - # rel.B.min <- (B.min / Btarg) |> - # round(digits = 2) - # - # # relative B max - # rel.B.max <- (B.max / Btarg) |> - # round(digits = 2) - - # TODO: uncomment and recode once we get clarity about how to extract this value properly - ## mortality (F) plot - # F reference point - # F.ref.pt <- dat |> - # dplyr::filter( - # label == stringr::str_to_lower("F_targ") | - # label == stringr::str_to_lower("F_proxy") | - # label == stringr::str_to_lower("F_msy") | - # label == "F_target" - # # label == "F40" - # # label == "F30" - # # label == "F50" - # # label == "F_initial" - # # label == "Fmsy" - # ) |> - # dplyr::filter(module_name == "DERIVED_QUANTITIES" | module_name == "parms") |> - # dplyr::pull(estimate) |> - # as.numeric() |> - # round(digits = 2) - - # start year of F plot - F.start.year <- dat |> - dplyr::filter(label == "fishing_mortality") |> - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() - - # terminal fishing mortality - # F.end.year : added with add_more_key_quants - - # minimum F - F.min <- dat |> - dplyr::filter(label == "fishing_mortality") - - if (length(unique(F.min$age)) == 1) { - if (is.na(unique(F.min$age))) { - F.min <- F.min |> - dplyr::filter(module_name %in% c("TIME_SERIES", "t.series")) |> - dplyr::slice(which.min(estimate)) |> - as.numeric() |> - round(digits = 2) - } - } else { - F.min <- F.min |> - dplyr::group_by(age) |> - dplyr::summarize(val = max(estimate)) |> - dplyr::slice(which.min(val)) |> - dplyr::select(val) |> - as.numeric() |> - round(digits = 2) - } - - - # maximum F - F.max <- dat |> - dplyr::filter(label == "fishing_mortality") - - if (length(unique(F.max$age)) == 1) { - if (is.na(unique(F.max$age))) { - F.min <- F.min |> - dplyr::filter(module_name %in% c("TIME_SERIES", "t.series")) |> - dplyr::slice(which.max(estimate)) |> - as.numeric() |> - round(digits = 2) - } - } else { - F.max <- F.max |> - dplyr::group_by(age) |> - dplyr::summarize(val = max(estimate)) |> - dplyr::slice(which.max(val)) |> - dplyr::select(val) |> - as.numeric() |> - round(digits = 2) - } - - # TODO: uncomment and recode once we get clarity about how to extract this value properly - # fishing mortality at msy - # Ftarg <- dat |> - # dplyr::filter(grepl('f_target', label) | - # grepl('f_msy', label) | - # c(grepl('fishing_mortality_msy', label) & is.na(year))) |> - # dplyr::pull(estimate) |> - # as.numeric() |> - # round(digits = 2) - - # Terminal year F respective to F target - # F.Ftarg : added with add_more_key_quants - - - ## landings plot - - # start year of landings plot - landings.start.year <- dat |> - dplyr::filter( - c(module_name == "t.series" & grepl("landings_observed", label)) | c(module_name == "CATCH" & grepl("ret_bio", label)), - # t.series is associated with a conversion from BAM output and CATCH with SS3 converted output - !is.na(fleet) - ) |> - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() - - # end year of landings plot - landings.end.year <- dat |> - dplyr::filter( - c(module_name == "t.series" & grepl("landings_observed", label)) | c(module_name == "CATCH" & grepl("ret_bio", label)), - # t.series is associated with a conversion from BAM output and CATCH with SS3 converted output - !is.na(fleet) - ) |> - dplyr::slice(which.max(year)) |> - dplyr::select(year) |> - as.numeric() - - # units of landings (plural) - # landings.units : added with add_more_key_quants - - # minimum landings - landings.min <- dat |> - dplyr::filter( - c(module_name == "t.series" & grepl("landings_observed", label)) | c(module_name == "CATCH" & grepl("ret_bio", label)), - # t.series is associated with a conversion from BAM output and CATCH with SS3 converted output - !is.na(fleet) - ) |> - dplyr::slice(which.min(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - # maximum landings - landings.max <- dat |> - dplyr::filter( - c(module_name == "t.series" & grepl("landings_observed", label)) | c(module_name == "CATCH" & grepl("ret_bio", label)), - # t.series is associated with a conversion from BAM output and CATCH with SS3 converted output - !is.na(fleet) - ) |> - dplyr::group_by(fleet, year) |> - dplyr::summarise(max_est = max(estimate)) |> - dplyr::filter(!is.na(max_est)) |> - dplyr::group_by(year) |> - dplyr::summarise(max_est_yr = sum(max_est)) |> - dplyr::slice(which.max(max_est_yr)) |> - dplyr::select(max_est_yr) |> - as.numeric() |> - round(digits = 2) - - ## natural mortality (M)- bam examples have label as natural_mortality - ## but other formats don't (in input) - # minimum age of M - if ("natural_mortality" %in% dat$label) { - M.age.min <- dat |> - dplyr::filter(label == "natural_mortality") |> - dplyr::select(age) |> - dplyr::filter(!is.na(age)) |> - dplyr::slice(which.min(age)) |> - as.numeric() - } else { - M.age.min <- dat |> - # dplyr::filter(label == "natural_mortality") |> - dplyr::select(age) |> - dplyr::filter(!is.na(age)) |> - dplyr::slice(which.min(age)) |> - as.numeric() - } - - # maximum age of M - if ("natural_mortality" %in% dat$label) { - M.age.max <- dat |> - dplyr::filter(label == "natural_mortality") |> - dplyr::select(age) |> - dplyr::filter(!is.na(age)) |> - dplyr::slice(which.max(age)) |> - as.numeric() - } else { - M.age.max <- dat |> - # dplyr::filter(label == "natural_mortality") |> - dplyr::select(age) |> - dplyr::filter(!is.na(age)) |> - dplyr::slice(which.max(age)) |> - as.numeric() - } - - # minimum M rate- don't code quantities yet (see how it's coded in future fig) - # M.rate.min <- dat |> - # dplyr::filter( - # grepl("natural_mortality", label)) |> - # -label = natural_mortality (min); est in est col - - # maximum M rate- don't code quantities yet (see how it's coded in future fig) - # M.rate.max <- - # -label = natural_mortality (min); est in est col - - - ## vonB LAA (von Bertalanffy growth function + length at age)- don't code quantities yet - # vonb.age.min <- # minimum vonB age - # vonb.age.max <- # maximum vonB age - - # vonB length units (plural) - # vonb.length.units : added with add_more_key_quants - - # vonb.length.min <- # minimum vonB length - # vonb.length.max <- # minimum vonB length - - - ## length-type conversion plot- don't code quantities yet - # total length units (plural) - # total.length.units : added with add_more_key_quants - - # total.length.min <- # minimum total length - # total.length.max <- # maximum total length - # fork length units (plural) - # fork.length.units : added with add_more_key_quants - - # fork.length.min <- # minimum fork length - # fork.length.max <- # maximum fork length - - - ## weight-length conversion plot- don't code quantities yet - # length units (plural) - # wl.length.units : added with add_more_key_quants - - # wl.length.min <- # minimum length - # wl.length.max <- # maximum length - - # weight units (plural) - # wl.weight.units : added with add_more_key_quants - - # wl.weight.min <- # minimum weight - # wl.weight.max <- # maximum weight - - - ## maturity schedule (proportion mature)- don't code quantities yet - # length units (plural) - # prop.mat.length.units : added with add_more_key_quants - - # prop.mat.length.min <- # minimum length - # prop.mat.length.max <- # maximum length - - - ## fecundity at length- don't code quantities yet - # length units (plural) - # fecundity.length.units : added with add_more_key_quants - - # fecundity.length.min <- # minimum length - # fecundity.length.max <- # maximum length - - # fecundity units (plural) - # fecundity.units : added with add_more_key_quants - - # fecundity.min <- # minimum fecundity - # fecundity.max <- # maximum fecundity - - - ## catch at age (CAA) - # start year of CAA plot - caa.start.year <- dat |> - dplyr::filter(label == "abundance" & !is.na(year)) |> - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() - - # end year of CAA plot - caa.end.year <- dat |> - dplyr::filter(label == "abundance" & !is.na(year)) |> - dplyr::slice(which.max(year)) |> - dplyr::select(year) |> - as.numeric() - - # minimum age - caa.age.min <- dat |> - dplyr::filter(label == "abundance" & !is.na(year)) |> - dplyr::slice(which.min(age)) |> - dplyr::select(age) |> - as.numeric() - - # maximum age - caa.age.max <- dat |> - dplyr::filter(label == "abundance" & !is.na(year)) |> - dplyr::slice(which.max(age)) |> - dplyr::select(age) |> - as.numeric() - - - ## catch composition - # minimum & maximum catch - if (dim(dat |> - dplyr::filter(label == "catch"))[1] > 1) { - catch <- dat |> - dplyr::filter( - label == "catch", - !is.na(fleet) - ) |> - dplyr::mutate( - estimate = as.numeric(estimate), - year = as.numeric(year), - fleet = as.factor(fleet) - ) |> - dplyr::group_by(label, year, fleet) |> - dplyr::summarise(estimate = sum(estimate)) |> - dplyr::ungroup() - - tot.catch.min <- catch |> - dplyr::slice(which.min(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - tot.catch.max <- catch |> - dplyr::slice(which.max(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - } else { - tot.catch.min <- "NA" - tot.catch.max <- "NA" - } - - ## CAL (catch at length)- don't code quantities yet - # cal.length.min <- # minimum length group - # cal.length.max <- # maximum length group - # fleet.or.survey.name <- # fleet or survey name - - - ## CPUE indices plot- don't code quantities yet - # cpue.start.year <- # start year of CPUE indices plot - # cpue.end.year <- # end year of CPUE indices plot - - # CPUE units (plural) (SHARED with mod.fit.abun, below) - # cpue.units : added with add_more_key_quants - - # cpue.min <- # minimum CPUE (SHARED with mod_fit_abun, below) - # cpue.max <- # maximum CPUE (SHARED with mod_fit_abun, below) - - - ## NAA (numbers at age) - # start year of NAA plot - pop.naa.start.year <- dat |> - dplyr::filter(label == "abundance" & !is.na(year)) |> - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() - - # end year of NAA plot - pop.naa.end.year <- dat |> - dplyr::filter( - label == "abundance" & !is.na(year), - era == "time" - ) |> - dplyr::slice(which.max(year)) |> - dplyr::select(year) |> - as.numeric() - - # minimum age - pop.naa.age.min <- dat |> - dplyr::filter(label == "abundance" & !is.na(year)) |> - dplyr::slice(which.min(age)) |> - dplyr::select(age) |> - as.numeric() - - # maximum age - pop.naa.age.max <- dat |> - dplyr::filter(label == "abundance" & !is.na(year)) |> - dplyr::slice(which.max(age)) |> - dplyr::select(age) |> - as.numeric() - - # minimum abundance (number) of fish - pop.naa.fish.min <- dat |> - dplyr::filter( - grepl("abundance", label) & !is.na(year), - era == "time" - ) |> - dplyr::slice(which.min(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - # maximum abundance (number) of fish - pop.naa.fish.max <- dat |> - dplyr::filter( - grepl("abundance", label) & !is.na(year), - era == "time" - ) |> - dplyr::slice(which.max(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - ## mod_fit_catch (model fit to catch ts)- don't code quantities yet - # mod.fit.catch.start.year <- # start year of model fit to catch ts plot - # mod.fit.catch.end.year <- # end year of model fit to catch ts plot - - # catch units (plural) - # mod.fit.catch.units : added with add_more_key_quants - - # mod.fit.catch.min <- # minimum catch - # mod.fit.catch.max <- # maximum catch - - - ## mod_fit_abun (model fit to abundance indices plot)- don't code quantities yet - # start year of model fit to abundance indices plot - # mod.fit.abun.start.year <- - - # end year of model fit to abundance indices plot - # mod.fit.abun.end.year <- - - ## mod_fit_discards- will be by fleet - ## for ss3, obs discards not in output file - ## -filter labels as discard_observed | discard_predicted | discard - ## -then group_by(year, fleet, label), then summarize(estimate_y = sum(estimate)) - ## ---then, get the following: - ## -change alt text so that we add the line's min/max, but analyst has to describe further - # mod.fit.discards.start.year <- # start year of model fit to discards plot - # mod.fit.discards.end.year <- # end year of F - # mod.fit.discards.units <- # discards units (plural) - # mod.fit.discards.min <- # minimum discards - # mod.fit.discards.max <- # maximum discards - - ## selectivity- don't code quantities yet - # selectivity.start.year <- # start year of selectivity plot - # selectivity.end.year <- # end year of selectivity plot - # selectivity.length.units <- # length units (plural) - # selectivity.length.min <- # minimum length - # selectivity.length.max <- # maximum length - - - ## estimated stock recruitment - # youngest-age recruited fish (instead of age-0) - sr.age.min <- dat |> - dplyr::filter(!is.na(year) & !is.na(age)) |> - dplyr::slice(which.min(age)) |> - dplyr::select(age) |> - as.numeric() - - # ssb units (plural) - # sr.ssb.units : added with add_more_key_quants - - # minimum ssb : added with add_more_key_quants - - # maximum ssb : added with add_more_key_quants - - # recruitment units (plural) - # sr.units : added with add_more_key_quants - - # minimum recruitment : added with add_more_key_quants - - # maximum recruitment: added with add_more_key_quants - - ## recruitment ts - # recruitment units (plural) - numbers of fish, in thousands - # recruitment.units : added with add_more_key_quants - - # start year of recruitment ts plot - recruitment.start.year <- dat |> - dplyr::filter( - label == "recruitment", - module_name == "TIME_SERIES" | module_name == "t.series", - !is.na(year), - is.na(fleet) | length(unique(fleet)) <= 1, - is.na(sex) | length(unique(sex)) <= 1, - is.na(area) | length(unique(area)) <= 1, - is.na(growth_pattern) | length(unique(growth_pattern)) <= 1, - !year %in% year_exclusions - ) |> # SS3 and BAM target module names - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() - - # end year of recruitment ts plot - # recruitment.end.year : added with add_more_key_quants - - # TODO: uncomment and recode once we get clarity about how to extract R0 properly - ## relative recruitment - # # minimum relative recruitment - # rel.recruitment.min <- (sr.min / R0) |> - # round(digits = 2) - # - # # maximum relative recruitment - # rel.recruitment.max <- (sr.max / R0) |> - # round(digits = 2) - - - ## recruitment deviations - # start year of recruitment deviations plot - recruit.dev.start.year <- dat |> - dplyr::filter( - label == "recruitment_deviations" | label == "log_recruitment_deviations", - module_name == "SPAWN_RECRUIT" | module_name == "t.series", - !is.na(year), - is.na(fleet) | length(unique(fleet)) <= 1, - is.na(sex) | length(unique(sex)) <= 1, - is.na(area) | length(unique(area)) <= 1, - is.na(growth_pattern) | length(unique(growth_pattern)) <= 1, - !year %in% year_exclusions - ) |> # SS3 and BAM target module names - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() - - # end year of recruitment deviations plot - # recruit.dev.end.year : added with add_more_key_quants - - # minimum recruitment deviation - recruit.dev.min <- dat |> - dplyr::filter( - label == "recruitment_deviations" | label == "log_recruitment_deviations", - module_name == "SPAWN_RECRUIT" | module_name == "t.series", - !is.na(year), - is.na(fleet) | length(unique(fleet)) <= 1, - is.na(sex) | length(unique(sex)) <= 1, - is.na(area) | length(unique(area)) <= 1, - is.na(growth_pattern) | length(unique(growth_pattern)) <= 1, - !year %in% year_exclusions - ) |> # SS3 and BAM target module names - dplyr::slice(which.min(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - # maximum recruitment deviation - recruit.dev.max <- dat |> - dplyr::filter( - label == "recruitment_deviations" | label == "log_recruitment_deviations", - module_name == "SPAWN_RECRUIT" | module_name == "t.series", - !is.na(year), - is.na(fleet) | length(unique(fleet)) <= 1, - is.na(sex) | length(unique(sex)) <= 1, - is.na(area) | length(unique(area)) <= 1, - is.na(growth_pattern) | length(unique(growth_pattern)) <= 1, - !year %in% year_exclusions - ) |> # SS3 and BAM target module names - dplyr::slice(which.max(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - ## tot_b (total biomass): same as B plot above - - ## spawning_biomass (ssb) - # start year of ssb plot - ssb.start.year <- dat |> - dplyr::filter( - label == "spawning_biomass", - module_name %in% c("DERIVED_QUANTITIES", "t.series") - ) |> - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() |> - round(digits = 2) - - # end year of ssb plot - # ssb.end.year : added with add_more_key_quants - - # ssb units (plural) - # ssb.units : added with add_more_key_quants - - # minimum ssb - # ssb.min : added with add_more_key_quants - - # maximum ssb - # ssb.max : added with add_more_key_quants - - # ssb reference point - # ssb.ref.pt : added with add_more_key_quants - - # ssbtarg : added with add_more_key_quants - - ## relative ssb - # relative ssb min - # rel.ssb.min : added with add_more_key_quants - - # relative ssb max - # rel.ssb.max : added with add_more_key_quants - - - ## spr (spawning potential ratio) - # minimum spr - spr.min <- dat |> - dplyr::filter(c(grepl("spr", label) | - label == "spr") & - !is.na(year) & - !is.na(estimate)) |> - dplyr::slice(which.min(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - # maximum spr - spr.max <- dat |> - dplyr::filter(c(grepl("spr", label) | - label == "spr") & !is.na(year) & !is.na(estimate)) |> - dplyr::slice(which.max(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - # TODO: uncomment and recode once we get clarity about how to extract this value properly - # spr reference point - # spr.ref.pt <- dat |> - # dplyr::filter(label == "spr_msy") |> - # dplyr::select(estimate) |> - # as.numeric()# |> - # round(digits = 2) - - - ## pop.baa (population biomass at age) - # start year of pop.baa plot - pop.baa.start.year <- dat |> - dplyr::filter(grepl("^biomass", label)) |> - dplyr::slice(which.min(year)) |> - dplyr::select(year) |> - as.numeric() - - # end year of pop.baa plot - pop.baa.end.year <- dat |> - dplyr::filter( - grepl("^biomass", label), - era == "time" - ) |> - dplyr::slice(which.max(year)) |> - dplyr::select(year) |> - as.numeric() - - # minimum biomass of fish - pop.baa.fish.min <- dat |> - dplyr::filter( - grepl("^biomass", label) & !is.na(year), - era == "time" - ) |> - dplyr::slice(which.min(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - # maximum biomass of fish - pop.baa.fish.max <- dat |> - dplyr::filter( - grepl("^biomass", label) & !is.na(year), - era == "time" - ) |> - dplyr::slice(which.max(estimate)) |> - dplyr::select(estimate) |> - as.numeric() |> - round(digits = 2) - - # minimum age - pop.baa.age.min <- dat |> - dplyr::filter( - label == "biomass", - module_name == "BIOMASS_AT_AGE" | module_name == "B.age", # SS3 and BAM target module names - !is.na(age) - ) |> - dplyr::slice(which.min(age)) |> - dplyr::select(age) |> - as.numeric() - - # maximum age - pop.baa.age.max <- dat |> - dplyr::filter( - label == "biomass", - module_name == "BIOMASS_AT_AGE" | module_name == "B.age", # SS3 and BAM target module names - !is.na(age) - ) |> - dplyr::slice(which.max(age)) |> - dplyr::select(age) |> - as.numeric() - - - ## proj_catch (projected catch) - # projected catch units (plural) - # proj.catch.units <- # probably mt, but wait until figure coded - # --then add into add_more_key_quants() - - # start year of projected catch plot - proj.catch.start.year <- landings.end.year + 1 - - # end year of projected catch plot - proj.catch.end.year <- dat |> - dplyr::filter(label == "catch" & module_name == "DERIVED_QUANTITIES") |> - dplyr::slice(which.max(year)) |> - dplyr::select(year) |> - as.numeric() - - # minimum projected catch - proj.catch.min <- dat |> - # no BAM file has catch; will be NA - dplyr::filter(label == "catch" & module_name == "DERIVED_QUANTITIES") |> - dplyr::slice(which.min(estimate)) |> - dplyr::select(estimate) |> - as.numeric() - - # maximum projected catch - proj.catch.max <- dat |> - dplyr::filter(label == "catch" & module_name == "DERIVED_QUANTITIES") |> - dplyr::slice(which.max(estimate)) |> - dplyr::select(estimate) |> - as.numeric() - - # TABLES----- - - ## catch - # catch.fleet <- # fleet - - ## landings - # landings.tbl.units <- # landings units; remove if units already in table - - ## discards - # discards.tbl.units <- # discards units - - ## catchability - # catchability.fleet <- # fleet - - - # add in more quantities here, and update the quantities above - - # substitute quantity placeholders in the captions/alt text with - # the real values, extracted above - - - # make list with all placeholders - # uncomment placeholders once uncommented, above - patterns_replacements <- c( - # FIGURES----- - - ## kobe plot - # 'kobe.end.year' = as.character(kobe.end.year), - # 'B.BMSY.end.yr' = as.character(B.BMSY.end.yr), - # 'F.FMSY.end.yr' = as.character(F.FMSY.end.yr), - # 'overfished.status.is.isnot' = as.character(overfished.status.is.isnot), - # 'overfishing.status.is.isnot' = as.character(overfishing.status.is.isnot), - - ## Relative biomass plot - # NOTE: moving this above biomass so rel.B.min isn't changed to "rel." + B.min (etc.) - # 'rel.B.min' = as.character(rel.B.min), - # 'rel.B.max' = as.character(rel.B.max), - - ## Biomass plot - "B.start.year" = as.character(B.start.year), - # 'R0' = as.character(R0), - # 'Bend' = as.character(Bend), - # 'Btarg' = as.character(Btarg), - # 'Bmsy' = as.character(Bmsy), - - ## mortality (F) plot - # 'F.ref.pt' = as.character(F.ref.pt), - "F.start.year" = as.character(F.start.year), - "F.min" = as.character(F.min), - "F.max" = as.character(F.max), - # 'Ftarg' = as.character(Ftarg), - - ## landings plot - "landings.start.year" = as.character(landings.start.year), - "landings.end.year" = as.character(landings.end.year), - "landings.min" = as.character(landings.min), - "landings.max" = as.character(landings.max), - - ## natural mortality (M) - "M.age.min" = as.character(M.age.min), - "M.age.max" = as.character(M.age.max), - # 'M.rate.min' = as.character(M.rate.min), - # 'M.rate.max' = as.character(M.rate.max), - - ## vonB LAA (von Bertalanffy growth function + length at age) - # 'vonb.age.min' = as.character(vonb.age.min), - # 'vonb.age.max' = as.character(vonb.age.max), - # 'vonb.length.units' = as.character(vonb.length.units), - # 'vonb.length.min' = as.character(vonb.length.min), - # 'vonb.length.max' = as.character(vonb.length.max), - - ## length-type conversion plot - # 'total.length.units' = as.character(total.length.units), - # 'total.length.min' = as.character(total.length.min), - # 'total.length.max' = as.character(total.length.max), - # 'fork.length.units' = as.character(fork.length.units), - # 'fork.length.min' = as.character(fork.length.min), - # 'fork.length.max' = as.character(fork.length.max), - - ## weight-length conversion plot - # 'wl.length.units' = as.character(wl.length.units), - # 'wl.length.min' = as.character(wl.length.min), - # 'wl.length.max' = as.character(wl.length.max), - # 'wl.weight.units' = as.character(wl.weight.units), - # 'wl.weight.min' = as.character(wl.weight.min), - # 'wl.weight.max' = as.character(wl.weight.max), - - ## maturity schedule (proportion mature) - # 'prop.mat.length.units' = as.character(prop.mat.length.units), - # 'prop.mat.length.min' = as.character(prop.mat.length.min), - # 'prop.mat.length.max' = as.character(prop.mat.length.max), - - ## fecundity at length - # 'fecundity.length.units' = as.character(fecundity.length.units), - # 'fecundity.length.min' = as.character(fecundity.length.min), - # 'fecundity.length.max' = as.character(fecundity.length.max), - # 'fecundity.units' = as.character(fecundity.units), - # 'fecundity.min' = as.character(fecundity.min), - # 'fecundity.max' = as.character(fecundity.max), - - ## CAA (catch at age) - "caa.start.year" = as.character(caa.start.year), - "caa.end.year" = as.character(caa.end.year), - "caa.age.min" = as.character(caa.age.min), - "caa.age.max" = as.character(caa.age.max), - - - ## catch comp - "tot.catch.min" = as.character(tot.catch.min), - "tot.catch.max" = as.character(tot.catch.max), - - ## CAL (catch at length) - # 'cal.length.min' = as.character(cal.length.min), - # 'cal.length.max' = as.character(cal.length.max), - # 'fleet.or.survey.name' = as.character(fleet.or.survey.name), - - ## CPUE indices plot - # 'cpue.start.year' = as.character(cpue.start.year), - # 'cpue.end.year' = as.character(cpue.end.year), - # 'cpue.min' = as.character(cpue.min), - # 'cpue.max' = as.character(cpue.max), - - ## NAA (numbers at age) - "pop.naa.start.year" = as.character(pop.naa.start.year), - "pop.naa.end.year" = as.character(pop.naa.end.year), - "pop.naa.age.min" = as.character(pop.naa.age.min), - "pop.naa.age.max" = as.character(pop.naa.age.max), - "pop.naa.fish.min" = as.character(pop.naa.fish.min), - "pop.naa.fish.max" = as.character(pop.naa.fish.max), - - ## mod_fit_catch (model fit to catch ts) - # 'mod.fit.catch.start.year' = as.character(mod.fit.catch.start.year), - # 'mod.fit.catch.end.year' = as.character(mod.fit.catch.end.year), - # 'mod.fit.catch.units' = as.character(mod.fit.catch.units), - # 'mod.fit.catch.min' = as.character(mod.fit.catch.min), - # 'mod.fit.catch.max' = as.character(mod.fit.catch.max), - - ## mod_fit_abun (model fit to abundance indices plot) - # 'mod.fit.abun.start.year' = as.character(mod.fit.abun.start.year), - # 'mod.fit.abun.end.year' = as.character(mod.fit.abun.end.year), - - ## mod_fit_discards - # 'mod.fit.discards.start.year' = as.character(mod.fit.discards.start.year), - # 'mod.fit.discards.end.year' = as.character(mod.fit.discards.end.year), - # 'mod.fit.discards.units' = as.character(mod.fit.discards.units), - # 'mod.fit.discards.min' = as.character(mod.fit.discards.min), - # 'mod.fit.discards.max' = as.character(mod.fit.discards.max), - - ## selectivity - # 'selectivity.start.year' = as.character(selectivity.start.year), - # 'selectivity.end.year' = as.character(selectivity.end.year), - # 'selectivity.length.units' = as.character(selectivity.length.units), - # 'selectivity.length.min' = as.character(selectivity.length.min), - # 'selectivity.length.max' = as.character(selectivity.length.max), - - ## estimated stock recruitment (aka spawning stock biomass) - # 'sr.age.min' = as.character(sr.age.min), - - # relative recruitment ts - # NOTE: moving this above recruitment so rel.recruitment.min isn't changed - # to "rel." + recruitment.min (etc.) - # 'rel.recruitment.min' = as.character(rel.recruitment.min), - # 'rel.recruitment.max' = as.character(rel.recruitment.max), - - ## recruitment ts - "recruitment.start.year" = as.character(recruitment.start.year), - - ## recruitment deviations - "recruit.dev.start.year" = as.character(recruit.dev.start.year), - "recruit.dev.min" = as.character(recruit.dev.min), - "recruit.dev.max" = as.character(recruit.dev.max), - - ## spawning.biomass (ssb) - "ssb.start.year" = as.character(ssb.start.year), - - ## spr (spawning potential ratio) - "spr.min" = as.character(spr.min), - "spr.max" = as.character(spr.max), - # 'spr.ref.pt' = as.character(spr.ref.pt), - - # ## pop.baa (population biomass at age) - "pop.baa.start.year" = as.character(pop.baa.start.year), - "pop.baa.end.year" = as.character(pop.baa.end.year), - "pop.baa.fish.min" = as.character(pop.baa.fish.min), - "pop.baa.fish.max" = as.character(pop.baa.fish.max), - "pop.baa.age.min" = as.character(pop.baa.age.min), - "pop.baa.age.max" = as.character(pop.baa.age.max), - - - ## proj_catch (projected catch) - # 'proj.catch.units' = as.character(proj.catch.units), - "proj.catch.start.year" = as.character(proj.catch.start.year), - "proj.catch.end.year" = as.character(proj.catch.end.year), - "proj.catch.min" = as.character(proj.catch.min), - "proj.catch.max" = as.character(proj.catch.max) # , - - # # TABLES----- - # - # ## catch - # 'catch.fleet' = as.character(catch.fleet), - # - # ## landings - # 'landings.tbl.units' = as.character(landings.tbl.units), - # - # ## discards - # 'discards.tbl.units' = as.character(discards.tbl.units), - # - # ## catchability - # 'catchability.fleet' = as.character(catchability.fleet) - ) - - # If a value in patterns_replacements = NA, then make it "NA" - # to avoid errors - patterns_replacements <- tidyr::replace_na(patterns_replacements, "NA") - - # take the values associated with the quantities and replace the df's - # placeholders with them. For example, if ssb_min = 10, this will replace - # "the minimum ssb = ssb_min" with "the minimum ssb = 10". - - # replace values in caption column - caps_alttext$caption <- stringr::str_replace_all( - caps_alttext$caption, - patterns_replacements - ) - - # replace values in alt text column - caps_alttext$alt_text <- stringr::str_replace_all( - caps_alttext$alt_text, - patterns_replacements - ) - - # export df with updated captions and alt text to csv - utils::write.csv( - x = caps_alttext, - file = fs::path( - dir, - "captions_alt_text.csv" - ), - row.names = FALSE - ) - - - # message explaining the extracted and inserted key quantities - replaced_vals <- patterns_replacements |> - as.data.frame() |> - tibble::rownames_to_column() |> - dplyr::rename( - "name" = 1, - "key_quantity" = 2 - ) - - cli::cli_h3("Key quantities extracted and inserted from write_captions().") - cli::cli_alert_info("NA values signify key quantities that were not extracted and inserted.", wrap = TRUE) - for (i in 1:dim(replaced_vals)[1]) { - cli::cli_li(paste0( - replaced_vals[i, 1], - ": ", - replaced_vals[i, 2] - )) - } - - # enable warnings again - options(warn = 0) - } -} diff --git a/inst/resources/captions_alt_text_template.csv b/inst/resources/captions_alt_text_template.csv index ae5cc77f..d5ea858c 100644 --- a/inst/resources/captions_alt_text_template.csv +++ b/inst/resources/captions_alt_text_template.csv @@ -1,11 +1,11 @@ label,type,caption,alt_text kobe,figure,"Kobe plot showing stock status. Triangles delineate start and end years. Horizontal and vertical dashed lines delineate the proportion of F/F~MSY~ where F~MSY~ = B.ref.pt, and B/B~MSY~ where B~MSY~ = B.ref.pt. Overfishing is occurring when F/F~MSY~ > 1 and an overfished status is indicated where B/B~MSY~ > 1.","A Kobe plot showing stock status. The x axis shows overfished status (i.e., B/B~MSY~) and the y axis shows overfishing (i.e., F/F~MSY~). The B/B~MSY~ and F/F~MSY~ for kobe.end.year were B.BMSY.end.yr and F.FMSY.end.yr, respectively, indicating that the stock overfished.status.is.isnot overfished and overfishing.status.is.is.not experiencing overfishing." biomass,figure,Biomass (B) time series. The horizontal dashed line represents the limit reference point (B.ref.pt B.units).,"Line graph showing biomass time series. The x axis shows the year, which spans from B.start.year to B.end.year . The y axis shows biomass in B.units, which spans from B.min to B.max." -relative.biomass,figure,Relative biomass (B) time series. The horizontal dashed line represents the limit reference point calculated as B/B(reference point) (B.ref.point B.units).,"Line graph showing relative biomass time series. The x axis shows the year, which spans from B.start.year to B.end.year . The y axis shows relative biomass (B/B~target~), which spans from rel.B.min to rel.B.max B.units ." -fishing.mortality,figure,Fishing mortality (F) over time. The horizontal dashed line represents the target reference point (F.ref.pt).,"Line graph showing fishing mortality over time . The x axis shows the year, which spans from F.start.year to F.end.year . The y axis shows fishing mortality in F.units, which spans from F.min to F.max." -relative.fishing.mortality,figure,Relative fishing mortality (F) over time. The horizontal dashed line represents the target reference point (F.ref.pt).,"Line graph showing fishing mortality over time . The x axis shows the year, which spans from F.start.year to F.end.year . The y axis shows relative fishing mortality (F/F~target~), which spans from rel.F.min to rel.F.max." +relative_biomass,figure,Relative biomass (B) time series. The horizontal dashed line represents the limit reference point calculated as B/B(reference point) (B.ref.point B.units).,"Line graph showing relative biomass time series. The x axis shows the year, which spans from B.start.year to B.end.year . The y axis shows relative biomass (B/B~target~), which spans from rel.B.min to rel.B.max B.units ." +fishing_mortality,figure,Fishing mortality (F) over time. The horizontal dashed line represents the target reference point (F.ref.pt).,"Line graph showing fishing mortality over time . The x axis shows the year, which spans from F.start.year to F.end.year . The y axis shows fishing mortality in F.units, which spans from F.min to F.max." +relative_fishing_mortality,figure,Relative fishing mortality (F) over time. The horizontal dashed line represents the target reference point (F.ref.pt).,"Line graph showing fishing mortality over time . The x axis shows the year, which spans from F.start.year to F.end.year . The y axis shows relative fishing mortality (F/F~target~), which spans from rel.F.min to rel.F.max." landings,figure,Historical landings by fleet.,"Cumulative area plot showing historical landings. The x axis shows the year, which spans from landings.start.year to landings.end.year . The y axis shows landings in landings.units, which spans from landings.min to landings.max." -natural.mortality,figure,Natural mortality (M) for each age. ,"Line graph showing natural mortality. The x axis shows age in years, which spans from M.age.min to M.age.max. The y axis shows the natural mortality rate per year, which spans from M.rate.min to M.rate.max." +natural_mortality,figure,Natural mortality (M) for each age. ,"Line graph showing natural mortality. The x axis shows age in years, which spans from M.age.min to M.age.max. The y axis shows the natural mortality rate per year, which spans from M.rate.min to M.rate.max." vonb.laa,figure,Aged and measured fish (points) and von Bertalanffy growth function (line) fit to the data.,"Point and line graph showing observations of measured age and length data as points and the von Bertalanffy relationship fit to this data as a line with 95\\% confidence intervals. The x axis shows age in years, which spans from vonb.age.min to vonb.age.max. The y axis shows length in vonb.length.units, which spans from vonb.length.min to vonb.length.max." length.type.conversion,figure,Length-type conversion relationship between total and fork length where points represent individual fish length measurement observations and the line is the fitted relationship.,"Point and line graph showing observations of measured fork length and measured total length from the same fish for conversion purposes as points, and a linear fit through those points as a line. The x axis shows total length in total.length.units, which spans from total.length.min to total.length.max. The y axis shows fork length in fork.length.units, which spans from fork.length.min to fork.length.max." weight.length.converstion,figure,Weight-length conversion relationship where the points represent individual fish observations and the line is the fitted relationship. ,"Point and line graph showing observations of measured length and measured weight from the same fish for conversion purposes as points, and an exponential fit through those points as a line. The x axis shows length in wl.length.units, which spans from wl.length.min to wl.length.max. The y axis shows weight in wl.weight.units, which spans from wl.weight.min to wl.weight.max." @@ -13,22 +13,22 @@ maturity.schedule,figure,The relationship between the proportion mature and fish fecundity.at.length,figure,Fecundity (in number of eggs) as a function of fish length. ,"Point and line graph showing observations of measured fecundity and measured length from the same fish and an exponential fit through those points displayed as a line. The x axis shows length in fecundity.length.units, which spans from fecundity.length.min to fecundity.length.max. The y axis shows fecundity in fecundity.units, which spans from fecundity.min to fecundity.max." catch,figure,"Historical catch for each year in which there is composition data, for each fleet or survey.","Cumulative area plot showing the catch for each year and fleet or survey. The x axis shows the year, which spans from catch.year.min to catch.year.max. The y axis shows the proportion of the total catch by each fleet or survey and spans from tot.catch.min to tot.catch.max." CAL,figure,"Histograms showing the proportion of the catch in each length group, each year for which there is composition data, for fleet or survey fleet.or.survey.name.","Histograms for each year and fleet for which there is data (one per year grouped by fleet or survey), which show the proportion of the catch in each length group. The x axis of each histogram contains length intervals, which span from cal.length.min to cal.length.max. The y axis of each histogram contains the proportion of the catch and spans from 0--1." -CPUE.indices,figure,Catch per unit effort (CPUE) over time for fleet or survey. 95\\% confidence intervals are shown for each survey/fleet.,"Line graph showing catch per unit effort (CPUE) over time, stratified by survey/fleet. The x axis shows the year, which spans from cpue.start.year to cpue.end.year . The y axis shows CPUE in cpue.units, which spans from cpue.min to cpue.max." -pop.naa,figure,Model estimate of population numbers at age over time. The relative size of each bubble for a given year and age indicates the relative abundance in that category compared with others. ,"Bubble plot showing relative age proportions over time. The x axis shows the year, which spans from pop.naa.start.year to pop.naa.end.year . The y axis shows age in years, which spans from pop.naa.age.min to pop.naa.age.max. The size of the bubbles range from pop.naa.fish.min to pop.naa.fish.max." +indices,figure,Catch per unit effort (CPUE) over time for fleet or survey. 95\\% confidence intervals are shown for each survey/fleet.,"Line graph showing catch per unit effort (CPUE) over time, stratified by survey/fleet. The x axis shows the year, which spans from cpue.start.year to cpue.end.year . The y axis shows CPUE in cpue.units, which spans from cpue.min to cpue.max." +abundance_at_age,figure,Model estimate of population numbers at age over time. The relative size of each bubble for a given year and age indicates the relative abundance in that category compared with others. ,"Bubble plot showing relative age proportions over time. The x axis shows the year, which spans from pop.naa.start.year to pop.naa.end.year . The y axis shows age in years, which spans from pop.naa.age.min to pop.naa.age.max. The size of the bubbles range from pop.naa.fish.min to pop.naa.fish.max." mod.fit.catch,figure,Observed catch from the data input file (points) and model estimated catch (line) over time for fleet.or.survey.name. ,"Point and line graph showing observed catch from the data input file as points and model estimated catch as a line over time for fleet.or.survey.name. The x axis shows years, which spans from mod.fit.catch.start.year to mod.fit.catch.end.year . The y axis shows catch in mod.fit.catch.units, which spans from mod.fit.catch.min to mod.fit.catch.max." mod.fit.abun,figure,Assessment model fits to input catch per unit of effort index values over time calculated from fleet.or.survey.name.,"Point and line graph showing the assessment model fit, displayed as a line, to input catch per unit effort index values, displayed as points over time, for fleet.or.survey.name. The x axis shows years, which spans from mod.fit.abun.start.year to mod.fit.abun.end.year . The y axis shows catch per unit effort in cpue.units, which spans from cpue.min to cpue.max." mod.fit.discards,figure,Observed discards (points) and estimated discards (line).,"Point and line graph showing the assessment model fit to observed discards. Observed discards are represented as points while the model fitted estimates are represented as a line over time for fleet.or.survey.name. The x axis shows the year, which spans from mod.fit.discards.start.year to mod.fit.discards.end.year . The y axis shows discards in mod.fit.discards.units, which spans from mod.fit.discards.min to mod.fit.discards.max." selectivity,figure,Length-based selectivity for each fleet and survey estimated by the assessment model.,"Line graph showing length-based selectivity for fleet.or.survey.name from selectivity.start.year to selectivity.end.year . The x axis shows length in selectivity.length.units, which spans from selectivity.length.min to selectivity.length.max. The y axis shows the proportion of the stock that the gear selects for, which spans from 0--1." -sr,figure,Stock recruitment relationship estimated by the assessment model. ,"Point and line graph showing the relationship between stock biomass and newly recruited sr.age.min fish as estimated by the assessment model. Points represent model estimates of recruitment each year as a function of stock biomass, after adjusted by annual recruitment deviations. The line represents the best fit through the points for the stock relationship selected for use in the assessment model. The x axis shows spawning stock biomass in sr.ssb.units, which spans from sr.ssb.min to sr.ssb.max. The y axis shows recruitment in sr.units, which spans from sr.min to sr.max." +stock_recruitment,figure,Stock recruitment relationship estimated by the assessment model. ,"Point and line graph showing the relationship between stock biomass and newly recruited sr.age.min fish as estimated by the assessment model. Points represent model estimates of recruitment each year as a function of stock biomass, after adjusted by annual recruitment deviations. The line represents the best fit through the points for the stock relationship selected for use in the assessment model. The x axis shows spawning stock biomass in sr.ssb.units, which spans from sr.ssb.min to sr.ssb.max. The y axis shows recruitment in sr.units, which spans from sr.min to sr.max." recruitment,figure,Estimated recruitment by the assessment model each year in recruitment.units.,"Line graph showing the assessment model estimated recruitment in sr.units for each year. The x axis shows years, which spans from recruitment.start.year to recruitment.end.year . The y axis shows recruitment in recruitment.units, which spans from sr.min to sr.max." recruitment.comp,figure,Predicted (black points) and expected (red line) recruitment by the assessment model each year in recruitment.units.,"Scatter plot showing the assessment model estimated recruitment in sr.units for each year with a red line showing the predicted recruitment in sr.units for each year. The x axis shows years, which spans from recruitment.start.year to recruitment.end.year . The y axis shows recruitment in recruitment.units, which spans from sr.min to sr.max." relative.recruitment,figure,"Estimated relative recruitment by the assessment model each year in recruitment.units, calculated as R/R~0~ where R~0~ is R0.","Line graph showing the assessment model estimated relative recruitment in sr.units for each year. The x axis shows year, which spans from recruitment.start.year to recruitment.end.year . The y axis shows relative recruitment (R/R~0~), which spans from rel.recruitment.min to rel.recruitment.max recruitment.units ." -recruitment.deviations,figure,Annual deviations (on natural log scale) in the number of newly recruited fish the model estimates each year. ,"Scatterplot showing annual deviations in recruitment. Points have error bars and the dashed horizontal line at 0 represents no deviation from what would be estimated by the stock-recruit relationship. Positive values represent an increase in recruitment that year while negative values represent a decrease. The x axis shows year, which spans from recruit.dev.start.year to recruit.dev.end.year . The y axis shows the recruitment deviation, which spans from recruit.dev.min to recruit.dev.max on a natural log scale." +recruitment_deviations,figure,Annual deviations (on natural log scale) in the number of newly recruited fish the model estimates each year. ,"Scatterplot showing annual deviations in recruitment. Points have error bars and the dashed horizontal line at 0 represents no deviation from what would be estimated by the stock-recruit relationship. Positive values represent an increase in recruitment that year while negative values represent a decrease. The x axis shows year, which spans from recruit.dev.start.year to recruit.dev.end.year . The y axis shows the recruitment deviation, which spans from recruit.dev.min to recruit.dev.max on a natural log scale." tot.b,figure,Estimated biomass (B) time series. The horizontal dashed line represents the biomass limit reference point at B.ref.pt B.units.,"Line graph showing estimated biomass time series. The x axis shows the year, which spans from B.start.year to B.end.year . The y axis shows estimated biomass in B.units, which spans from B.min to B.max." -spawning.biomass,figure,Estimated spawning stock biomass (SSB) time series. The horizontal dashed line represents the spawning stock biomass associated with the biomass limit reference point (ssb.ref.pt ssb.units).,"Line graph showing estimated spawning stock biomass. The x axis shows the year, which spans from ssb.start.year to ssb.end.year . The y axis shows estimated spawning stock biomass in ssb.units, which spans from ssb.min to ssb.max." +spawning_biomass,figure,Estimated spawning stock biomass (SSB) time series. The horizontal dashed line represents the spawning stock biomass associated with the biomass limit reference point (ssb.ref.pt ssb.units).,"Line graph showing estimated spawning stock biomass. The x axis shows the year, which spans from ssb.start.year to ssb.end.year . The y axis shows estimated spawning stock biomass in ssb.units, which spans from ssb.min to ssb.max." relative.spawning.biomass,figure,Estimated relative spawning stock biomass time series. The horizontal dashed line represents the limit reference point calculated as SSB/SSB(reference point) (ssb.ref.pt ssb.units).,"Line graph showing estimated relative spawning stock biomass. The x axis shows the year, which spans from ssb.start.year to ssb.end.year . The y axis shows estimated relative spawning stock biomass (SSB/SSB~target~), which spans from rel.ssb.min to rel.ssb.max ssb.units." spr,figure,Estimated spawning potential ratio (SPR) (SSB~current~/SSB~target~) time series. The horizontal dashed line represents the spawning potential ratio of the limit reference point at spr.ref.pt.,"Line graph showing estimated spawning potential ratio over time. The x axis shows the year, which spans from ssb.start.year to ssb.end.year . The y axis shows estimated spawning potential ratio in SSB~current~/SSB~target~, which spans from spr.min to spr.max." -pop.baa,figure,Estimated population numbers at age and population biomass at age over time. The relative size of each bubble for a given year and age indicates the relative abundance or biomass in that category compared with others. ,"Bubble plot showing estimated population numbers at age and population biomass at age. The x axis shows the year, which spans from pop.baa.start.year to pop.baa.end.year . The y axis shows age, which spans from pop.baa.age.min to pop.baa.age.max. The size of the bubbles range from pop.baa.fish.min to pop.baa.fish.max." +biomass_at_age,figure,Estimated population numbers at age and population biomass at age over time. The relative size of each bubble for a given year and age indicates the relative abundance or biomass in that category compared with others. ,"Bubble plot showing estimated population numbers at age and population biomass at age. The x axis shows the year, which spans from pop.baa.start.year to pop.baa.end.year . The y axis shows age, which spans from pop.baa.age.min to pop.baa.age.max. The size of the bubbles range from pop.baa.fish.min to pop.baa.fish.max." proj.catch,figure,Forecasted catch in proj.catch.units over future years for different fishing mortality scenarios as indicated in the legend.,"Time series line graph showing forecasted catch over future years for different fishing mortality scenarios. The x axis shows the year, which spans from proj.catch.start.year to proj.catch.end.year . The y axis shows catch in proj.catch.units, which spans from proj.catch.min to proj.catch.max." proj.biomass,table,Forecasted biomass over future years for different fishing mortality scenarios., report.version.model.changes,table,Document version history briefly describing when major changes or updates are made to each version of the report., @@ -38,7 +38,7 @@ life.history.params,table,Life history parameters used in the stock assessment m landings,table,Landed catch by fleet and year in landings.units., discards,table,Discarded catch by fleet and year in discards.tbl.units., age.length.key,table,Age-length key: the proportion of fish for each age that belong to a particular length group. , -indices.abundance,table,Calculated indices of abundance and their corresponding CVs for the fleets and surveys identified in the column headers. , +indices,table,Calculated indices of abundance and their corresponding CVs for the fleets and surveys identified in the column headers. , model.runs,table,"The base configuration and alternative sensitivity analysis configurations of the stock assessment model, in which parameters and/or data input streams are changed from one configuration to another.", derived.quantities,table,Derived quantities calculated by the base configuration of the stock assessment model., est.params,table,Parameters used in the base stock assessment model and whether the parameter was estimated by the model or fixed (i.e. not allowed to be estimated or changed by the model). CVs for estimated models are provided., @@ -47,4 +47,4 @@ bnc,table,"Historical biomass, spawning biomass, abundance, and catch time ser naa,table,Historical population abundance (numbers) estimated by the base model for each age group., catchability,table,Catchability over time for fleet catchability.fleet., sensitivity.runs,table,"Forecasted catch, biomass, spawning biomass, recruitment, fishing mortality, and stock status as projected from the base model configuration.", -pop.caa,figure,Fishery age composition (caa.start.year-caa.end.year). The area of the circle is proportional to the catch. Diagonal lines indicated the top 5\\% strongest year classes.,"Bubble plot showing estimated total catch at age. The x axis shows the year, which spans from caa.start.year to caa.end.year . The y axis shows age, which spans from caa.age.min to caa.age.max. The size of the bubbles range from tot.catch.min to tot.catch.max." +catch_comp,figure,Fishery age composition (caa.start.year-caa.end.year). The area of the circle is proportional to the catch. Diagonal lines indicated the top 5\\% strongest year classes.,"Bubble plot showing estimated total catch at age. The x axis shows the year, which spans from caa.start.year to caa.end.year . The y axis shows age, which spans from caa.age.min to caa.age.max. The size of the bubbles range from tot.catch.min to tot.catch.max." diff --git a/man/write_captions.Rd b/man/write_captions.Rd index 5dcb7fc3..78bcee4a 100644 --- a/man/write_captions.Rd +++ b/man/write_captions.Rd @@ -1,11 +1,9 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils_rda.R, R/write_captions.R +% Please edit documentation in R/utils_rda.R \name{write_captions} \alias{write_captions} \title{Write captions and alternative text} \usage{ -write_captions(dat, dir = getwd(), year = format(Sys.Date(), "\%Y")) - write_captions(dat, dir = getwd(), year = format(Sys.Date(), "\%Y")) } \arguments{ @@ -20,18 +18,11 @@ saved. Defaults to working directory.} being performed. Defaults to the current year.} } \value{ -Exports .csv with captions and alt text for figures and tables -that contain key quantities (e.g., an assessment's start year) that -are automatically extracted from the converted model results file. - Exports .csv with captions and alt text for figures and tables that contain key quantities (e.g., an assessment's start year) that are automatically extracted from the converted model results file. } \description{ -Function to create captions and alternative text that contain -key quantities from the model results file. - Function to create captions and alternative text that contain key quantities from the model results file. } @@ -42,10 +33,4 @@ write_captions(dat, year = 2025 ) } -\dontrun{ -write_captions(dat, - dir = getwd(), - year = 2025 -) -} } diff --git a/tests/testthat/fixtures/ss3_models_converted/Hake_2018/std_output.rda b/tests/testthat/fixtures/ss3_models_converted/Hake_2018/std_output.rda index 0b2e9206..cd52a36f 100644 Binary files a/tests/testthat/fixtures/ss3_models_converted/Hake_2018/std_output.rda and b/tests/testthat/fixtures/ss3_models_converted/Hake_2018/std_output.rda differ diff --git a/tests/testthat/test-plot_abundance_at_age.R b/tests/testthat/test-plot_abundance_at_age.R index fce1f13f..1961cffe 100644 --- a/tests/testthat/test-plot_abundance_at_age.R +++ b/tests/testthat/test-plot_abundance_at_age.R @@ -44,9 +44,9 @@ test_that("rda file made when indicated", { make_rda = TRUE ) - # expect that both figures dir and the pop.naa_figure.rda file exist + # expect that both figures dir and the abundance_at_age_figure.rda file exist expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "pop.naa_figure.rda"))) + expect_true(file.exists(fs::path(getwd(), "figures", "abundance_at_age_figure.rda"))) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv")) diff --git a/tests/testthat/test-plot_biomass_at_age.R b/tests/testthat/test-plot_biomass_at_age.R index 08f72016..4ff946ff 100644 --- a/tests/testthat/test-plot_biomass_at_age.R +++ b/tests/testthat/test-plot_biomass_at_age.R @@ -43,9 +43,9 @@ test_that("rda file made when indicated", { make_rda = TRUE ) - # expect that both figures dir and the pop.baa_figure.rda file exist + # expect that both figures dir and the biomass_at_age_figure.rda file exist expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "pop.baa_figure.rda"))) + expect_true(file.exists(fs::path(getwd(), "figures", "biomass_at_age_figure.rda"))) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv")) diff --git a/tests/testthat/test-plot_catch_comp.R b/tests/testthat/test-plot_catch_comp.R index 71c59c62..29e3cacc 100644 --- a/tests/testthat/test-plot_catch_comp.R +++ b/tests/testthat/test-plot_catch_comp.R @@ -44,9 +44,9 @@ test_that("rda file made when indicated", { make_rda = TRUE ) - # expect that both figures dir and the pop.naa_figure.rda file exist + # expect that both figures dir and the catch_comp_figure.rda file exist expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "pop.caa_figure.rda"))) + expect_true(file.exists(fs::path(getwd(), "figures", "catch_comp_figure.rda"))) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv")) diff --git a/tests/testthat/test-plot_indices.R b/tests/testthat/test-plot_indices.R new file mode 100644 index 00000000..d7384d84 --- /dev/null +++ b/tests/testthat/test-plot_indices.R @@ -0,0 +1,36 @@ +# load sample dataset +load(file.path( + "fixtures", "ss3_models_converted", "Hake_2018", + "std_output.rda" +)) + +test_that("plot_indices generates plots without errors", { + # expect error-free plot with minimal arguments + expect_no_error( + plot_indices(out_new) + ) + + + # expect ggplot object is returned + expect_s3_class( + plot_indices(out_new), + "gg" + ) +}) + +test_that("rda file made when indicated", { + # export rda + plot_indices(out_new, + make_rda = TRUE, + unit_label = "metric tons", + figures_dir = getwd() + ) + + # expect that both figures dir and the indices_figure.rda file exist + expect_true(dir.exists(fs::path(getwd(), "figures"))) + expect_true(file.exists(fs::path(getwd(), "figures", "indices_figure.rda"))) + + # erase temporary testing files + file.remove(fs::path(getwd(), "captions_alt_text.csv")) + unlink(fs::path(getwd(), "figures"), recursive = T) +}) diff --git a/tests/testthat/test-plot_landings.R b/tests/testthat/test-plot_landings.R index 421f763a..d6e62277 100644 --- a/tests/testthat/test-plot_landings.R +++ b/tests/testthat/test-plot_landings.R @@ -1,49 +1,37 @@ -# # load sample dataset -# load(file.path( -# "fixtures", "ss3_models_converted", "Hake_2018", -# "std_output.rda" -# )) +# load sample dataset +load(file.path( + "fixtures", "ss3_models_converted", "Hake_2018", + "std_output.rda" +)) -# test_that("plot_landings generates plots without errors", { -# # expect error-free plot with minimal arguments -# expect_no_error( -# plot_landings(out_new) -# ) +test_that("plot_landings generates plots without errors", { + # expect error-free plot with minimal arguments + expect_no_error( + plot_landings(out_new) + ) -# # expect ggplot object is returned -# expect_s3_class( -# plot_landings(out_new), -# "gg" -# ) -# }) + # expect ggplot object is returned + expect_s3_class( + plot_landings(out_new), + "gg" + ) +}) -# test_that("rda file made when indicated", { -# # export rda -# plot_landings(out_new, -# end_year = 2024, -# make_rda = TRUE, -# unit_label = "metric tons", -# figures_dir = getwd() -# ) +test_that("rda file made when indicated", { + # export rda + plot_landings(out_new, + end_year = 2024, + make_rda = TRUE, + unit_label = "metric tons", + figures_dir = getwd() + ) -# # expect that both figures dir and the landings_figure.rda file exist -# expect_true(dir.exists(fs::path(getwd(), "figures"))) -# expect_true(file.exists(fs::path(getwd(), "figures", "landings_figure.rda"))) + # expect that both figures dir and the landings_figure.rda file exist + expect_true(dir.exists(fs::path(getwd(), "figures"))) + expect_true(file.exists(fs::path(getwd(), "figures", "landings_figure.rda"))) -# # erase temporary testing files -# file.remove(fs::path(getwd(), "captions_alt_text.csv")) -# unlink(fs::path(getwd(), "figures"), recursive = T) -# }) - -# test_that("plot_landings generates error with future end_year", { -# # expect error -# expect_error( -# plot_landings(out_new, -# end_year = 2035, -# make_rda = TRUE, -# unit_label = "metric tons", -# figures_dir = getwd() -# ) -# ) -# }) + # erase temporary testing files + file.remove(fs::path(getwd(), "captions_alt_text.csv")) + unlink(fs::path(getwd(), "figures"), recursive = T) +}) diff --git a/tests/testthat/test-plot_natural_mortality.R b/tests/testthat/test-plot_natural_mortality.R index 534d692f..de9b5e5a 100644 --- a/tests/testthat/test-plot_natural_mortality.R +++ b/tests/testthat/test-plot_natural_mortality.R @@ -34,9 +34,9 @@ test_that("rda file made when indicated", { figures_dir = getwd() ) - # expect that both figures dir and the spawning.biomass_figure.rda file exist + # expect that both figures dir and the natural_mortality_figure.rda file exist expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "natural.mortality_figure.rda"))) + expect_true(file.exists(fs::path(getwd(), "figures", "natural_mortality_figure.rda"))) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv")) diff --git a/tests/testthat/test-plot_recruitment_deviations.R b/tests/testthat/test-plot_recruitment_deviations.R index defcfa2b..55f7a38f 100644 --- a/tests/testthat/test-plot_recruitment_deviations.R +++ b/tests/testthat/test-plot_recruitment_deviations.R @@ -43,9 +43,9 @@ test_that("rda file made when indicated", { figures_dir = getwd() ) - # expect that both figures dir and the recruitment.deviations_figure.rda file exist + # expect that both figures dir and the recruitment_deviations_figure.rda file exist expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "recruitment.deviations_figure.rda"))) + expect_true(file.exists(fs::path(getwd(), "figures", "recruitment_deviations_figure.rda"))) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv")) diff --git a/tests/testthat/test-plot_spawning_biomass.R b/tests/testthat/test-plot_spawning_biomass.R index 9844e11b..5fb2c7c4 100644 --- a/tests/testthat/test-plot_spawning_biomass.R +++ b/tests/testthat/test-plot_spawning_biomass.R @@ -89,9 +89,9 @@ test_that("rda file made when indicated", { figures_dir = getwd() ) - # expect that both figures dir and the spawning.biomass_figure.rda file exist + # expect that both figures dir and the spawning_biomass_figure.rda file exist expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "spawning.biomass_figure.rda"))) + expect_true(file.exists(fs::path(getwd(), "figures", "spawning_biomass_figure.rda"))) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv")) diff --git a/tests/testthat/test-plot_stock_recruitment.R b/tests/testthat/test-plot_stock_recruitment.R index 2fa0b11c..994f3e9a 100644 --- a/tests/testthat/test-plot_stock_recruitment.R +++ b/tests/testthat/test-plot_stock_recruitment.R @@ -49,7 +49,7 @@ test_that("rda file made when indicated", { # expect that both figures dir and the sr_figure.rda file exist expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "sr_figure.rda"))) + expect_true(file.exists(fs::path(getwd(), "figures", "stock_recruitment_figure.rda"))) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv")) diff --git a/tests/testthat/test-save_all_plots.R b/tests/testthat/test-save_all_plots.R index d58814e2..0de5c96e 100644 --- a/tests/testthat/test-save_all_plots.R +++ b/tests/testthat/test-save_all_plots.R @@ -10,7 +10,7 @@ test_that("save_all_plots works when all figures/tables are plotted", { recruitment_unit_label = "mt", recruitment_scale_amount = 1, ref_line = c("unfished" = 1000), - ref_line_sb = "target", + ref_line_sb = c("msy"), # indices_unit_label = "CPUE", figures_tables_dir = getwd(), interactive = FALSE @@ -23,33 +23,33 @@ test_that("save_all_plots works when all figures/tables are plotted", { # expect that the figures are all created with expected names fig_base_temp_files <- c( "biomass_figure.rda", - "CPUE.indices_figure.rda", - "fishing.mortality_figure.rda", + "indices_figure.rda", + "fishing_mortality_figure.rda", "landings_figure.rda", - "natural.mortality_figure.rda", - "pop.baa_figure.rda", - "pop.caa_figure.rda", - "pop.naa_figure.rda", + "natural_mortality_figure.rda", + "biomass_at_age_figure.rda", + "catch_comp_figure.rda", + "abundance_at_age_figure.rda", "recruitment_figure.rda", - "recruitment.deviations_figure.rda", - "spawning.biomass_figure.rda", - "sr_figure.rda" + "recruitment_deviations_figure.rda", + "spawning_biomass_figure.rda", + "stock_recruitment_figure.rda" ) expect_equal( sort(list.files(fs::path(getwd(), "figures"))), sort(fig_base_temp_files) ) - # expect that the tables are all created with expected names - # tab_base_temp_files <- c( - # "bnc_table.rda", - # "indices.abundance_table.rda", - # "landings_table.rda" - # ) - # expect_equal( - # list.files(fs::path(getwd(), "tables")), - # tab_base_temp_files - # ) + # # expect that the tables are all created with expected names + # tab_base_temp_files <- c( + # # "bnc_table.rda", + # # "indices.abundance_table.rda", + # "landings_table.rda" + # ) + # expect_equal( + # list.files(fs::path(getwd(), "tables")), + # tab_base_temp_files + # ) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv"))