Skip to content

Commit

Permalink
updated add_more_key_quants fxn to handle two units (arguments) speci…
Browse files Browse the repository at this point in the history
…fied in plot_spawn_recruitment, and added add_more_key_quants to plot_spawn_recruitment
  • Loading branch information
sbreitbart-NOAA committed Jan 15, 2025
1 parent ba4a93d commit 8077ef2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
11 changes: 11 additions & 0 deletions R/plot_spawn_recruitment.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ plot_spawn_recruitment <- function(
year = end_year)
}

# add more key quantities included as arguments in this fxn
add_more_key_quants(
topic = topic_label,
fig_or_table = fig_or_table,
dir = rda_dir,
end_year = end_year,
sr_ssb_units = spawning_biomass_label,
sr_recruitment_units = recruitment_label,
units = NULL
)

# extract this plot's caption and alt text
caps_alttext <- extract_caps_alttext(topic_label = topic_label,
fig_or_table = fig_or_table,
Expand Down
34 changes: 27 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ add_more_key_quants <- function(
dir = NULL,
end_year = NULL,
units = NULL,
sr_ssb_units = NULL,
sr_recruitment_units = NULL,
ref_pt = NULL){

# import csv
Expand All @@ -89,7 +91,7 @@ add_more_key_quants <- function(
type == fig_or_table)

# replace placeholders (e.g., if "end.year" is found in topic_alt, replace it with end_year)
## end_year
## end_year-----
### alt text
### this regex preserves the comma after the end year
topic_cap_alt <- topic_cap_alt |>
Expand All @@ -102,10 +104,8 @@ add_more_key_quants <- function(
dplyr::mutate(alt_text = stringr::str_replace_all(alt_text,
stringr::regex("\\S*end\\.year\\S*\\s*"),
end_year))



## units
## units-----
if(!is.null(units)){
### caption
### this regex preserves the closing ) after the units
topic_cap_alt <- topic_cap_alt |>
Expand All @@ -125,7 +125,27 @@ add_more_key_quants <- function(
dplyr::mutate(caption = stringr::str_replace_all(caption,
stringr::regex("\\S*units\\S*"),
as.character(units)))
}

if(!is.null(sr_ssb_units)){
### this is for plot_spawn_recruitment, since there are two units
#### replace sr.ssb.units with sr_ssb_units
topic_cap_alt <- topic_cap_alt |>
dplyr::mutate(alt_text = stringr::str_replace_all(alt_text,
"sr.ssb.units",
as.character(sr_ssb_units)))
}

if(!is.null(sr_recruitment_units)){
### this is for plot_spawn_recruitment, since there are two units
#### replace sr.units with sr_recruitment_units
topic_cap_alt <- topic_cap_alt |>
dplyr::mutate(alt_text = stringr::str_replace_all(alt_text,
"sr.units",
as.character(sr_recruitment_units)))
}

if(!is.null(units)){
### alt text
### this regex preserves the comma after the units
topic_cap_alt <- topic_cap_alt |>
Expand All @@ -140,7 +160,8 @@ add_more_key_quants <- function(
stringr::regex("\\S*units\\S*"),
as.character(units)))

## reference points
}
## reference points-----
### caption
### this regex preserves the opening ( before the ref pt
topic_cap_alt <- topic_cap_alt |>
Expand All @@ -161,4 +182,3 @@ add_more_key_quants <- function(
row.names=FALSE)

}

0 comments on commit 8077ef2

Please sign in to comment.