From 2d42cf1788c43a0b4a76db6c33afa583f83c75cb Mon Sep 17 00:00:00 2001 From: sbreitbart-NOAA Date: Mon, 27 Jan 2025 11:00:12 -0500 Subject: [PATCH] Extracted 2 more key quantities (min, max M rate) --- R/write_captions.R | 56 +++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/R/write_captions.R b/R/write_captions.R index 9b58ff1..563f4fe 100644 --- a/R/write_captions.R +++ b/R/write_captions.R @@ -284,28 +284,48 @@ write_captions <- function(dat, # converted model output object round(digits = 2) ## natural mortality (M)- bam examples have label as natural_mortality - ## but other formats don't (in input) (use if statement) + ## but other formats don't (in input) # minimum age of M - # M.age.min <- dat |> - # dplyr::select(age) |> - # dplyr::filter(!is.na(age)) |> - # dplyr::slice(which.min(age)) |> - # as.numeric() - # - # # maximum age of M - # M.age.max <- dat |> - # dplyr::select(age) |> - # dplyr::filter(!is.na(age)) |> - # dplyr::slice(which.max(age)) |> - # as.numeric() - - # minimum M rate + 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 + # 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 @@ -837,8 +857,8 @@ write_captions <- function(dat, # converted model output object '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.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),