Skip to content
Merged
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
26 changes: 13 additions & 13 deletions R/convert_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
#'
#' Format stock assessment output file to a standardized tibble.
#'
#' @param file Path. Assessment model output file path. Currently accepts SS3
#' @param file Path. Assessment model output file path. Currently accepts SS3
#' Report.sso file, BAM .rda file, Rceattle model object, and FIMS model object.
#' @param model String. Assessment model used in evaluation
#'
#' Default: NULL
#'
#' Options: "ss3", "bam", "fims", "rceattle"
#' @param fleet_names Character vector. Names of fleets in the assessment model as
#' shortened in the output file or names of fleets to replace the native fleet
#' names in the output. For example, if fleet names in the model are 1, 2, 3
#' shortened in the output file or names of fleets to replace the native fleet
#' names in the output. For example, if fleet names in the model are 1, 2, 3
#' then fleet_names = c("fleet1" = 1, "fleet2" = 2, "fleet3" = 3).
#'
#' Default: NULL
#' @param save_dir Path. Full file path to save the converted output file. If
#' saved file name is not indicated, the file will be saved as "std_output.rda"
#' @param save_dir Path. Full file path to save the converted output file. If
#' saved file name is not indicated, the file will be saved as "std_output.rda"
#' in the file path provided.
#'
#' Default: NULL
Expand Down Expand Up @@ -297,7 +297,7 @@ convert_output <- function(
# Extract start year and end year
start_year <- file$startyr
end_year <- file$endyr

param_names <- names(dat)

std <- c(
Expand Down Expand Up @@ -667,10 +667,10 @@ convert_output <- function(
TRUE ~ label
),
estimate = suppressWarnings(as.numeric(estimate))
# dplyr::if_else(
# grepl("-|_", as.numeric(estimate)),
# NA,
# estimate
# dplyr::if_else(
# grepl("-|_", as.numeric(estimate)),
# NA,
# estimate
# )
)

Expand Down Expand Up @@ -1168,8 +1168,8 @@ convert_output <- function(
# df2[setdiff(tolower(names(out_new)), tolower(names(df2)))] <- NA
# # Add to out list
# out_list[[parm_sel]] <- df2
# } else
if (parm_sel == "DEFINITIONS") {
# } else
if (parm_sel == "DEFINITIONS") {
# Extract start year and end year for iding era
start_year <- as.numeric(extract[which(apply(extract, 1, function(row) any(row == "Start_year:"))), 2])
end_year <- as.numeric(extract[which(apply(extract, 1, function(row) any(row == "End_year:"))), 2])
Expand Down Expand Up @@ -1430,7 +1430,7 @@ convert_output <- function(
year < start_year ~ "init",
year >= start_year & year <= end_year ~ "time",
year > end_year ~ "fore",
TRUE ~ NA_character_
TRUE ~ NA_character_
)
)
} else if (model %in% c("bam", "BAM")) {
Expand Down
30 changes: 15 additions & 15 deletions R/html_all_figs_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
#' cli::cli_alert_info("Did you enter the correct argument for figures_tables_dir?")
#' cli::cli_alert_info("figures_tables_dir entered as {figures_tables_dir}")
#' }
#'
#'
#' if (!dir.exists(fs::path(figures_tables_dir, "tables"))) {
#' cli::cli_alert_danger("'tables' folder not found.")
#' cli::cli_alert_warning("Tables will not be included in the html.")
#' cli::cli_alert_info("Did you enter the correct argument for figures_tables_dir?")
#' cli::cli_alert_info("figures_tables_dir entered as {figures_tables_dir}")
#' }
#'
#'
#' # check if dir exists and present warning message/option message
#' if (dir.exists(fs::path(figures_tables_dir, "all_tables_figures"))) {
#' question1 <- readline(
Expand All @@ -45,33 +45,33 @@
#' # indicate to proceed with function
#' question1 <- "y"
#' }
#'
#'
#' if (regexpr(question1, "y", ignore.case = TRUE) == 1) {
#' # create new folder for the html and qmd files
#' doc_path <- fs::path(figures_tables_dir, "all_tables_figures")
#' dir.create(doc_path)
#'
#'
#' asar::create_tables_doc(
#' subdir = figures_tables_dir,
#' tables_dir = figures_tables_dir
#' )
#'
#'
#' asar::create_figures_doc(
#' subdir = figures_tables_dir,
#' figures_dir = figures_tables_dir
#' )
#'
#'
#' tab_doc_name <- list.files(figures_tables_dir)[grepl("_tables.qmd", list.files(figures_tables_dir))]
#' tab_doc <- readLines(fs::path(figures_tables_dir, tab_doc_name))
#'
#'
#' fig_doc_name <- list.files(figures_tables_dir)[grepl("_figures.qmd", list.files(figures_tables_dir))]
#' fig_doc <- readLines(fs::path(figures_tables_dir, fig_doc_name))
#'
#'
#' tabs_figs_text <- c(
#' tab_doc,
#' fig_doc
#' )
#'
#'
#' yaml_text <-
#' "---
#' title: 'All Tables & Figures'
Expand All @@ -81,38 +81,38 @@
#' embed-resources: true
#' ---
#' "
#'
#'
#' new_html_qmd <- c(yaml_text, tabs_figs_text)
#'
#'
#' writeLines(
#' new_html_qmd,
#' fs::path(figures_tables_dir, "all_tables_figures.qmd")
#' )
#'
#'
#' withr::with_dir(
#' figures_tables_dir,
#' quarto::quarto_render(
#' input = fs::path(figures_tables_dir, "all_tables_figures.qmd"),
#' output_file = fs::path("all_tables_figures.html")
#' )
#' )
#'
#'
#' file.rename(
#' from = fs::path(figures_tables_dir, "all_tables_figures.html"),
#' to = fs::path(
#' doc_path,
#' "all_tables_figures.html"
#' )
#' )
#'
#'
#' file.rename(
#' from = fs::path(figures_tables_dir, "all_tables_figures.qmd"),
#' to = fs::path(
#' doc_path,
#' "all_tables_figures.qmd"
#' )
#' )
#'
#'
#' cli::cli_alert_success("Generated html and qmd with all tables and figures", wrap = TRUE)
#' cli::cli_alert_info("Overwrote previous html and qmd")
#' } else {
Expand Down
72 changes: 45 additions & 27 deletions R/plot_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,38 @@ plot_biomass <- function(
B.ref.pt <- as.character(ref_line)
B.units <- as.character(unit_label)

B.start.year <- calc_kqs(returned_kq = "B.start.year",
prepared_data = prepared_data)
B.end.year <- calc_kqs(returned_kq = "B.end.year",
prepared_data = prepared_data)
B.terminal.year <- calc_kqs(returned_kq = "B.terminal.year",
dat = dat,
relative = relative,
module = selected_module)
B.terminal.est <- calc_kqs(returned_kq = "B.terminal.est",
dat = dat,
relative = relative,
module = selected_module)
B.terminal.min <- calc_kqs(returned_kq = "B.terminal.min",
dat = dat,
relative = relative,
module = selected_module)
B.terminal.max <- calc_kqs(returned_kq = "B.terminal.max",
dat = dat,
relative = relative,
module = selected_module)
B.start.year <- calc_kqs(
returned_kq = "B.start.year",
prepared_data = prepared_data
)
B.end.year <- calc_kqs(
returned_kq = "B.end.year",
prepared_data = prepared_data
)
B.terminal.year <- calc_kqs(
returned_kq = "B.terminal.year",
dat = dat,
relative = relative,
module = selected_module
)
B.terminal.est <- calc_kqs(
returned_kq = "B.terminal.est",
dat = dat,
relative = relative,
module = selected_module
)
B.terminal.min <- calc_kqs(
returned_kq = "B.terminal.min",
dat = dat,
relative = relative,
module = selected_module
)
B.terminal.max <- calc_kqs(
returned_kq = "B.terminal.max",
dat = dat,
relative = relative,
module = selected_module
)

# SS3, FIMS
if ("spawning_biomass_msy" %in% dat$label) {
Expand All @@ -242,13 +254,19 @@ plot_biomass <- function(
B.msy.max <- NA
# BAM
} else if ("bmsy" %in% dat$label) {
B.msy <- calc_kqs(returned_kq = "B.msy",
dat = dat)
B.msy.min <- calc_kqs(returned_kq = "B.msy.min",
dat = dat)
B.msy.max <- calc_kqs(returned_kq = "B.msy.max",
dat = dat)
# Rceattle
B.msy <- calc_kqs(
returned_kq = "B.msy",
dat = dat
)
B.msy.min <- calc_kqs(
returned_kq = "B.msy.min",
dat = dat
)
B.msy.max <- calc_kqs(
returned_kq = "B.msy.max",
dat = dat
)
# Rceattle
} else {
B.msy <- NA
B.msy.min <- NA
Expand Down
61 changes: 39 additions & 22 deletions R/plot_fishing_mortality.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,31 +116,48 @@ plot_fishing_mortality <- function(
F.start.year <- min(prepared_data$year)
F.end.year <- max(prepared_data$year)

F.terminal.year <- calc_kqs(returned_kq = "F.terminal.year",
F.terminal.year <- calc_kqs(
returned_kq = "F.terminal.year",
dat = dat,
module = selected_module
)

F.target <- calc_kqs(returned_kq = "F.target",
dat = dat)
F.limit <- calc_kqs(returned_kq = "F.limit",
dat = dat)
F.terminal.est <- calc_kqs(returned_kq = "F.terminal.est",
dat = dat,
module = selected_module)
F.terminal.min <- calc_kqs(returned_kq = "F.terminal.min",
dat = dat,
module = selected_module)
F.terminal.max <- calc_kqs(returned_kq = "F.terminal.max",
dat = dat,
module = selected_module)
F.MSY.terminal <- calc_kqs(returned_kq = "F.MSY.terminal",
dat = dat)
F.MSY.terminal.max <- calc_kqs(returned_kq = "F.MSY.terminal.max",
dat = dat)
F.MSY.terminal.min <- calc_kqs(returned_kq = "F.MSY.terminal.min",
dat = dat)


F.target <- calc_kqs(
returned_kq = "F.target",
dat = dat
)
F.limit <- calc_kqs(
returned_kq = "F.limit",
dat = dat
)
F.terminal.est <- calc_kqs(
returned_kq = "F.terminal.est",
dat = dat,
module = selected_module
)
F.terminal.min <- calc_kqs(
returned_kq = "F.terminal.min",
dat = dat,
module = selected_module
)
F.terminal.max <- calc_kqs(
returned_kq = "F.terminal.max",
dat = dat,
module = selected_module
)
F.MSY.terminal <- calc_kqs(
returned_kq = "F.MSY.terminal",
dat = dat
)
F.MSY.terminal.max <- calc_kqs(
returned_kq = "F.MSY.terminal.max",
dat = dat
)
F.MSY.terminal.min <- calc_kqs(
returned_kq = "F.MSY.terminal.min",
dat = dat
)

export_kqs(
F.ref.pt,
F.start.year,
Expand Down
Loading