Skip to content

Commit dc2cc92

Browse files
update(write_captions):
-change rounding to 2 digits -add comment describing how caps_alttext_subbed is created
1 parent 8978341 commit dc2cc92

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

R/write_captions.R

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ write_captions <- function(dat, # converted model output object
7676
dplyr::slice(which.min(estimate)) |>
7777
dplyr::select(estimate) |>
7878
as.numeric() |>
79-
round(digits = 0)
79+
round(digits = 2)
8080

8181
# maximum B
8282
B_max <- dat |>
@@ -88,14 +88,14 @@ write_captions <- function(dat, # converted model output object
8888
dplyr::slice(which.max(estimate)) |>
8989
dplyr::select(estimate) |>
9090
as.numeric() |>
91-
round(digits = 0)
91+
round(digits = 2)
9292

9393
# R0
9494
R0 <- dat |>
9595
dplyr::filter(grepl('R0', label) | grepl('recruitment_virgin', label)) |>
9696
dplyr::pull(estimate) |>
9797
as.numeric() |>
98-
round(digits = 0)
98+
round(digits = 2)
9999

100100
# Bend <-
101101

@@ -104,19 +104,19 @@ write_captions <- function(dat, # converted model output object
104104
dplyr::filter(c(grepl('biomass', label) & grepl('target', label) & estimate >1) | label == 'biomass_msy') |>
105105
dplyr::pull(estimate) |>
106106
as.numeric() |>
107-
round(digits = 0)
107+
round(digits = 2)
108108

109109
# Bmsy <-
110110

111111

112112
## relative B
113113
# relative B min
114114
rel_B_min <- (B_min / Btarg) |>
115-
round(digits = 0)
115+
round(digits = 2)
116116

117117
# relative B max
118118
rel_B_max <- (B_max / Btarg) |>
119-
round(digits = 0)
119+
round(digits = 2)
120120

121121

122122
## mortality (F) plot
@@ -178,7 +178,7 @@ write_captions <- function(dat, # converted model output object
178178
dplyr::slice(which.min(estimate)) |>
179179
dplyr::select(estimate) |>
180180
as.numeric() |>
181-
round(digits = 0)
181+
round(digits = 2)
182182

183183
# maximum landings
184184
landings_max <- dat |>
@@ -194,7 +194,7 @@ write_captions <- function(dat, # converted model output object
194194
dplyr::slice(which.max(estimate)) |>
195195
dplyr::select(estimate) |>
196196
as.numeric() |>
197-
round(digits = 0)
197+
round(digits = 2)
198198

199199
## natural mortality (M)
200200
# M_age_min <- # minimum age of M
@@ -313,7 +313,7 @@ write_captions <- function(dat, # converted model output object
313313
dplyr::slice(which.min(estimate)) |>
314314
dplyr::select(estimate) |>
315315
as.numeric() |>
316-
round(digits = 0)
316+
round(digits = 2)
317317

318318
# maximum ssb
319319
sr_ssb_max <- dat |>
@@ -331,7 +331,7 @@ write_captions <- function(dat, # converted model output object
331331
dplyr::slice(which.max(estimate)) |>
332332
dplyr::select(estimate) |>
333333
as.numeric() |>
334-
round(digits = 0)
334+
round(digits = 2)
335335

336336
# recruitment units (plural)
337337
# sr_units <- # this will take some thought, since recruitment_label
@@ -353,7 +353,7 @@ write_captions <- function(dat, # converted model output object
353353
dplyr::slice(which.min(estimate)) |>
354354
dplyr::select(estimate) |>
355355
as.numeric() |>
356-
round(digits = 0)
356+
round(digits = 2)
357357

358358
# maximum recruitment
359359
sr_max <- dat |>
@@ -371,16 +371,16 @@ write_captions <- function(dat, # converted model output object
371371
dplyr::slice(which.max(estimate)) |>
372372
dplyr::select(estimate) |>
373373
as.numeric() |>
374-
round(digits = 0)
374+
round(digits = 2)
375375

376376
## relative recruitment
377377
# minimum relative recruitment
378378
rel_recruitment_min <- (recruitment_min / R0) |>
379-
round(digits = 0)
379+
round(digits = 2)
380380

381381
# maximum relative recruitment
382382
rel_recruitment_max <- (recruitment_max / R0) |>
383-
round(digits = 0)
383+
round(digits = 2)
384384

385385

386386
## recruitment ts
@@ -453,7 +453,7 @@ write_captions <- function(dat, # converted model output object
453453
dplyr::slice(which.min(estimate)) |>
454454
dplyr::select(estimate) |>
455455
as.numeric() |>
456-
round(digits = 0)
456+
round(digits = 2)
457457

458458
# maximum recruitment deviation
459459
recruit_dev_max <- dat |>
@@ -469,7 +469,7 @@ write_captions <- function(dat, # converted model output object
469469
dplyr::slice(which.max(estimate)) |>
470470
dplyr::select(estimate) |>
471471
as.numeric() |>
472-
round(digits = 0)
472+
round(digits = 2)
473473

474474
## tot_b (total biomass)
475475
# biomass_start_year <- # start year of biomass plot
@@ -493,7 +493,7 @@ write_captions <- function(dat, # converted model output object
493493
dplyr::slice(which.min(year)) |>
494494
dplyr::select(year) |>
495495
as.numeric() |>
496-
round(digits = 0)
496+
round(digits = 2)
497497

498498
# end year of ssb plot
499499
# ssb_end_year <- # this will take some thought, since end_year is
@@ -515,7 +515,7 @@ write_captions <- function(dat, # converted model output object
515515
dplyr::slice(which.min(estimate)) |>
516516
dplyr::select(estimate) |>
517517
as.numeric() |>
518-
round(digits = 0)
518+
round(digits = 2)
519519

520520
# maximum ssb
521521
ssb_max <- dat |>
@@ -529,7 +529,7 @@ write_captions <- function(dat, # converted model output object
529529
dplyr::slice(which.max(estimate)) |>
530530
dplyr::select(estimate) |>
531531
as.numeric() |>
532-
round(digits = 0)
532+
round(digits = 2)
533533

534534
# ssb reference point
535535
# ssb_ref_pt <- # this will take some thought, since ref_line_val is
@@ -542,16 +542,16 @@ write_captions <- function(dat, # converted model output object
542542
dplyr::filter(c(grepl('spawning_biomass', label) & grepl('msy$', label) & estimate >1) | label == 'spawning_biomass_msy$') |>
543543
dplyr::pull(estimate) |>
544544
as.numeric() |>
545-
round(digits = 0)
545+
round(digits = 2)
546546

547547
## relative ssb
548548
# relative ssb min
549549
rel_ssb_min <- (ssb_min / ssbtarg) |>
550-
round(digits = 0)
550+
round(digits = 2)
551551

552552
# relative ssb max
553553
rel_ssb_max <- (ssb_max / ssbtarg) |>
554-
round(digits = 0)
554+
round(digits = 2)
555555

556556

557557
## spr (spawning potential ratio)
@@ -864,6 +864,9 @@ write_captions <- function(dat, # converted model output object
864864
# 'catchability_fleet' = catchability_fleet
865865
)
866866

867+
# take the values associated with the quantities and replace the df's
868+
# placeholders with them. For example, if ssb_min = 10, this will replace
869+
# "the minimum ssb = ssb_min" with "the minimum ssb = 10".
867870
caps_alttext_subbed <- caps_alttext |>
868871
dplyr::mutate(across(where(is.character), ~{
869872
for (pattern in names(patterns_replacements)){
@@ -873,7 +876,7 @@ write_captions <- function(dat, # converted model output object
873876
.
874877
}))
875878

876-
# export df with substituted captions and alt text to csv
879+
# export df with updated captions and alt text to csv
877880
utils::write.csv(x = caps_alttext_subbed,
878881
file = fs::path(dir,
879882
"captions_alt_text.csv"),

0 commit comments

Comments
 (0)