From df488be5a5524fa0ab59fba07f3e4a9b7b5c9d36 Mon Sep 17 00:00:00 2001 From: sbreitbart-NOAA <181890943+sbreitbart-NOAA@users.noreply.github.com> Date: Thu, 21 May 2026 14:42:54 +0000 Subject: [PATCH] style and docs: run devtools::document() and style with styler or air --- DESCRIPTION | 2 +- R/convert_output.R | 173 ++++++++++---------- R/data.R | 6 +- R/html_all_figs_tables.R | 4 +- R/plot_abundance_at_age.R | 32 ++-- R/plot_biomass.R | 18 +- R/plot_biomass_at_age.R | 8 +- R/plot_catch_comp.R | 16 +- R/plot_fishing_mortality.R | 11 +- R/plot_indices.R | 10 +- R/plot_landings.R | 8 +- R/plot_natural_mortality.R | 6 +- R/plot_recruitment.R | 8 +- R/plot_spawning_biomass.R | 48 +++--- R/plot_stock_recruitment.R | 44 ++--- R/process_data.R | 22 +-- R/save_all_plots.R | 86 +++++----- R/stockplotr-package.R | 2 +- R/table_landings.R | 12 +- R/utils.R | 27 ++- R/utils_plot.R | 33 ++-- R/utils_rda.R | 62 +++---- man/convert_output.Rd | 10 +- man/example_data.Rd | 2 +- man/plot_aa.Rd | 2 +- man/plot_biomass.Rd | 2 +- man/plot_landings.Rd | 2 +- man/plot_spawning_biomass.Rd | 2 +- man/process_data.Rd | 2 +- man/reference_line.Rd | 2 +- tests/testthat/test-plot_biomass.R | 2 +- tests/testthat/test-plot_spawning_biomass.R | 1 - tests/testthat/test-save_all_plots.R | 16 +- 33 files changed, 338 insertions(+), 343 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 02a7d01e..7ff57014 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -65,9 +65,9 @@ Suggests: testthat (>= 3.0.0) VignetteBuilder: knitr +Config/roxygen2/version: 8.0.0 Config/testthat/edition: 3 Config/testthat/parallel: false Encoding: UTF-8 Language: en-US LazyData: true -Config/roxygen2/version: 8.0.0 diff --git a/R/convert_output.R b/R/convert_output.R index e4efb507..e6e2fd5b 100644 --- a/R/convert_output.R +++ b/R/convert_output.R @@ -4,28 +4,28 @@ #' #' @param file Assessment model output file path #' @param model Assessment model used in evaluation -#' +#' #' Default: NULL -#' +#' #' Options: "ss3", "bam", "fims", "rceattle" #' @param fleet_names Names of fleets in the assessment model as #' shortened in the output file. If fleet names are not properly read, then #' indicate the fleets names as an acronym in a vector -#' +#' #' Default: NULL #' @param save_dir File path to save the converted output file. -#' +#' #' Default: NULL #' #' @author Samantha Schiano #' #' @returns A reformatted and standardized version of assessment model results #' for application in building a stock assessment reports and to easily -#' adapt results among regional assessments. -#' @details The resulting object is simply a transformed and machine readable -#' version of a model output file. Converted data frame is always returned. +#' adapt results among regional assessments. +#' @details The resulting object is simply a transformed and machine readable +#' version of a model output file. Converted data frame is always returned. #' It will also be saved if save_dir is not NULL. -#' +#' #' #' @export #' @@ -125,28 +125,27 @@ convert_output <- function( if (is.character(file)) { if (is.null(model)) { model <- switch(stringr::str_extract(file, "\\.([^.]+)$"), - ".sso" = { - cli::cli_alert_info("Processing Stock Synthesis output file...") - "ss3" - }, - ".rdat" = { - cli::cli_alert_info("Processing BAM output file...") - "bam" - }, - ".rds" = { - cli::cli_alert_info("Processing WHAM output file...") - "wham" - }, - ".RDS" = { - cli::cli_alert_info("Processing FIMS output file...") - "fims" - }, - - cli::cli_abort("Unknown file type. Please indicate model.") + ".sso" = { + cli::cli_alert_info("Processing Stock Synthesis output file...") + "ss3" + }, + ".rdat" = { + cli::cli_alert_info("Processing BAM output file...") + "bam" + }, + ".rds" = { + cli::cli_alert_info("Processing WHAM output file...") + "wham" + }, + ".RDS" = { + cli::cli_alert_info("Processing FIMS output file...") + "fims" + }, + cli::cli_abort("Unknown file type. Please indicate model.") ) } } else { - model <- switch (class(file)[1], + model <- switch(class(file)[1], "fims" = { cli::cli_alert_info("Processing FIMS output file...") "fims" @@ -158,7 +157,7 @@ convert_output <- function( cli::cli_abort("Unknown file type. Please indicate model.") ) } - + #### SS3 #### # Convert SS3 output Report.sso file @@ -1805,26 +1804,26 @@ convert_output <- function( } else { dat <- file } - + # Extract or use fleet names if (is.null(fleet_names)) { fleet_names <- names(dat$estimated_params$index_ln_q) } - + # Output fleet names in console cli::cli_alert_info("Identified fleet names:") cli::cli_alert_info("{fleet_names}") # Create list for morphed dfs to go into (for rbind later) out_list <- list() - + factors <- c("year", "fleet", "fleet_name", "age", "sex", "area", "seas", "season", "time", "era", "subseas", "subseason", "platoon", "platoo", "growth_pattern", "gp", "nsim", "age_a") errors <- c("StdDev", "sd", "se", "SE", "cv", "CV", "stddev") # units <- c("mt", "lbs", "eggs") - + ##### Loop #### for (p in (2:length(dat))[-c(6, 9, 10)]) { extract <- dat[p] - module_name <- names(extract) + module_name <- names(extract) cli::cli_alert_info("Processing {module_name}") if (module_name == "sdrep") { ##### sdrep #### @@ -1843,30 +1842,32 @@ convert_output <- function( values <- values |> dplyr::left_join( { - values |> dplyr::group_by(label) |> dplyr::count() + values |> + dplyr::group_by(label) |> + dplyr::count() }, by = "label" - ) + ) # make year column year_col <- rep( file[["data_list"]]$styr:file[["data_list"]]$projyr, length(unique( - dplyr::filter(values_count, n == length(file[["data_list"]]$styr:file[["data_list"]]$projyr)) |> + dplyr::filter(values_count, n == length(file[["data_list"]]$styr:file[["data_list"]]$projyr)) |> dplyr::pull(label) )) ) - + df2 <- values |> dplyr::filter(n == length(file[["data_list"]]$styr:file[["data_list"]]$projyr)) |> dplyr::mutate(year = year_col) - - df2 <- values |> - dplyr::filter( - n != length(file[["data_list"]]$styr:file[["data_list"]]$projyr) - ) |> - dplyr::mutate(year = NA) |> + + df2 <- values |> + dplyr::filter( + n != length(file[["data_list"]]$styr:file[["data_list"]]$projyr) + ) |> + dplyr::mutate(year = NA) |> rbind(df2) - + # Extract parameter values ts par_fixes <- data.frame( label = names(extract[[1]]$par.fixed), @@ -1879,23 +1880,23 @@ convert_output <- function( dplyr::left_join( par_fixes_count, by = "label" - ) - + ) + year_col_par_fix <- rep( file[["data_list"]]$styr:file[["data_list"]]$endyr, length(unique( - dplyr::filter(par_fixes_count, n == length(file[["data_list"]]$styr:file[["data_list"]]$endyr)) |> + dplyr::filter(par_fixes_count, n == length(file[["data_list"]]$styr:file[["data_list"]]$endyr)) |> dplyr::pull(label) )) ) - + df3 <- par_fixes |> dplyr::filter(n == length(file[["data_list"]]$styr:file[["data_list"]]$endyr)) |> dplyr::mutate(year = year_col_par_fix) - df3 <- par_fixes |> + df3 <- par_fixes |> dplyr::filter( n != length(file[["data_list"]]$styr:file[["data_list"]]$endyr) - ) |> + ) |> dplyr::mutate(year = NA) |> rbind(df3) |> dplyr::mutate( @@ -1905,13 +1906,13 @@ convert_output <- function( # not sure how pop_scalar is indexed # not sure how log_index_hat is indexes # Did not use r_sd for the error in rec bc used it from the other element in the list - + df4 <- rbind(df2, df3) |> dplyr::select(-n) |> dplyr::mutate( module_name = module_name ) - + df4[setdiff(tolower(names(out_new)), tolower(names(df4)))] <- NA out_list[[names(extract)]] <- df4 } else if (module_name == "data_list") { @@ -1919,9 +1920,9 @@ convert_output <- function( # Only extract specific quantity needs # comp_data?, index_data, catch_data, weight, Ftarget, Flimit data_list_list <- list() - + ####### Indices #### - # Extract index_data + # Extract index_data df_index <- extract[[1]]$index_data |> # rename all columns to lower case to match standard dplyr::rename_with(tolower) |> @@ -1938,7 +1939,7 @@ convert_output <- function( ) |> dplyr::select(-c(fleet_code, q_block)) cli::cli_alert_info("'Selectivity_block' values located in 'block' columns.") - + # check if species > 1 if (length(unique(df_index$species)) > 1) { cli::cli_abort("Not currently compatible for multispecies.") @@ -1946,7 +1947,7 @@ convert_output <- function( df_index <- df_index |> dplyr::select(-species) } - + # expand df long to have obs and pred in same column with label df_index_long <- df_index |> tidyr::pivot_longer( @@ -1955,19 +1956,19 @@ convert_output <- function( values_to = "estimate" ) |> dplyr::mutate( - module_name = names(extract)#, + module_name = names(extract) # , # era = dplyr::if_else( # year > dat$data_list$endyr, # "fore", # NA_character_ # ) ) - + df_index_long[setdiff(tolower(names(out_new)), tolower(names(df_index_long)))] <- NA data_list_list[["index_data"]] <- df_index_long - + ####### Catch indexing #### - # Extract catch_data and align with log_index_hat and catch_h + # Extract catch_data and align with log_index_hat and catch_h # Modify sdrep in outlist to include index df_catch <- extract[[1]]$catch_data |> # dplyr::filter(!is.na(Catch)) |> @@ -1995,28 +1996,28 @@ convert_output <- function( values_to = "estimate" ) |> dplyr::select(-c(fleet_code, species)) - + # Remove fleet names if do not match object # if (unique(df_catch$fleet) %notin% fleet_names) { # df_catch <- df_catch |> # dplyr::mutate(fleet = NA) # } - + if (length(unique(df_catch$month)) == 1) { df_catch$month <- NA } df_catch[setdiff(tolower(names(out_new)), tolower(names(df_catch)))] <- NA data_list_list[["catch_data"]] <- df_catch - + ####### Comp indexing #### df_comp_obs <- dat$data_list$comp_data |> dplyr::rename_with(tolower) |> dplyr::mutate( label = "indices_observed" ) - - indexing_vars_cols <- colnames(df_comp_obs)[!grepl("comp", colnames(df_comp_obs))] - + + indexing_vars_cols <- colnames(df_comp_obs)[!grepl("comp", colnames(df_comp_obs))] + df_comp_pred <- dplyr::select(df_comp_obs, dplyr::all_of(indexing_vars_cols)) |> dplyr::cross_join(as.data.frame(dat$quantities$age_hat)) |> tidyr::pivot_longer( @@ -2029,9 +2030,9 @@ convert_output <- function( dplyr::mutate( label = "composition_predicted", # NOTE: the below age mutate slows down code - age = stringr::str_replace(age, "V","") + age = stringr::str_replace(age, "V", "") ) - + # Finish adjusting comp_obs # pivot obs data df_comp_obs <- df_comp_obs |> @@ -2044,32 +2045,31 @@ convert_output <- function( dplyr::mutate( label = "composition_observed", # NOTE: the below age mutate slows down code - age = stringr::str_replace(age, "comp_","") + age = stringr::str_replace(age, "comp_", "") ) - + df_comp <- rbind(df_comp_obs, df_comp_pred) |> # TODO: do I need to filter sample size by <3 for confidentiality or does this not apply? dplyr::select(-c(age0_length1, fleet_code, sample_size)) - + df_catch[setdiff(tolower(names(out_new)), tolower(names(df_catch)))] <- NA data_list_list[["comp_data"]] <- df_catch - + # final df for data_list module new_df <- Reduce(rbind, data_list_list) out_list[[names(extract)]] <- new_df - } else if (is.list(extract[[1]])) { # indicates vector and list ##### remaining lmnts #### if (any(vapply(extract[[1]], is.matrix, FUN.VALUE = logical(1)))) { - ############################################################## + ############################################################## df <- extract[[1]] |> expand_element(fleet_names = fleet_names) |> dplyr::mutate( module_name = module_name - ) |> suppressWarnings() + ) |> + suppressWarnings() df[setdiff(tolower(names(out_new)), tolower(names(df)))] <- NA out_list[[names(extract)]] <- df - } else if (any(vapply(extract[[1]], is.vector, FUN.VALUE = logical(1)))) { # all must be a vector to work - so there must be conditions for dfs with a mix extract_list <- list() # mod_name1 <- names(extract) @@ -2079,7 +2079,7 @@ convert_output <- function( # mod_name2 <- glue::glue("{module_name}_{names(extract[[1]][i])}") # comment out message once finished development cli::cli_alert_info("Processing {names(extract[[1]][i])}") - + df <- extract[[1]][i][[1]] |> expand_element(fleet_names = fleet_names) |> dplyr::mutate( @@ -2109,12 +2109,12 @@ convert_output <- function( } else { cli::cli_alert_warning("Not compatible yet.") } - # } else if (is.list(extract[[1]])) { # list only - # } else if (is.matrix(extract[[1]])) { # matrix only - # } else { - # cli::cli_alert_warning(paste(names(extract), " not compatible.", sep = "")) - # } # close if statement - } # close loop over objects listed in dat file + # } else if (is.list(extract[[1]])) { # list only + # } else if (is.matrix(extract[[1]])) { # matrix only + # } else { + # cli::cli_alert_warning(paste(names(extract), " not compatible.", sep = "")) + # } # close if statement + } # close loop over objects listed in dat file # Finish out df out_new <- Reduce(rbind, out_list) |> # Add era as factor into BAM conout @@ -2123,12 +2123,11 @@ convert_output <- function( label = tolower(label), # set era era = dplyr::if_else( - year > dat$data_list$endyr, + year > dat$data_list$endyr, "fore", "time" ) ) - } else { cli::cli_abort(c( message = "Output file not compatible.", @@ -2184,13 +2183,13 @@ convert_output <- function( # con_file <- system.file("resources", "rceattle_var_names.csv", package = "stockplotr", mustWork = TRUE) # var_names_sheet <- utils::read.csv(con_file, na.strings = "") # } - + # edit: here is a different way of loading in the csv sheets con_file <- system.file("resources", glue::glue("{model}_var_names.csv"), package = "stockplotr", mustWork = TRUE) # temporarily add call to local csv so I can test # con_file <- glue::glue("~/GitHub/stockplotr/inst/resources/{model}_var_names.csv") var_names_sheet <- utils::read.csv(con_file, na.strings = "") - + if (file.exists(con_file)) { # Remove 'X' column if it exists var_names_sheet <- var_names_sheet |> diff --git a/R/data.R b/R/data.R index 3f758d14..ffc31b2c 100644 --- a/R/data.R +++ b/R/data.R @@ -1,6 +1,6 @@ #' SS3 Example data #' -#' Included data set that represents a Report.sso file converted using +#' Included data set that represents a Report.sso file converted using #' convert_output(). This example is from the 2022 Petrale sole stock assessment. #' #' @format A tibble with 591109 rows and 33 variables: @@ -39,5 +39,5 @@ #' \item{count}{indexing column of data} #' \item{block}{indexing column of data} #' } -#' -"example_data" \ No newline at end of file +#' +"example_data" diff --git a/R/html_all_figs_tables.R b/R/html_all_figs_tables.R index dbd66981..813bfa1a 100644 --- a/R/html_all_figs_tables.R +++ b/R/html_all_figs_tables.R @@ -9,11 +9,11 @@ #' #' @returns A folder ("all_tables_figures") in your working directory containing #' html and qmd files that show all tables and figures. -#' +#' #' @seealso #' \code{\link[asar:create_figures_doc]{asar::create_figures_doc()}}, #' \code{\link[asar:create_tables_doc]{asar::create_tables_doc()}} -#' +#' #' #' @export #' diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index 2c38be90..0fd7d7d0 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -3,51 +3,51 @@ #' @param dat A data frame returned from \link[stockplotr]{convert_output} #' @param facet a string or vector of strings of a column that facets the data. #' Set facet = "none" to summarize the data in a single plot. -#' +#' #' Default: NULL -#' +#' #' Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", #' NULL -#' +#' #' @param unit_label units for abundance -#' +#' #' Default: "fish" -#' +#' #' @param scale_amount A number describing how much to scale down the abundance at #' age. Please choose a value ranging from 1-1,000,000,000 (one billion) in orders #' of magnitude (e.g., 1, 10, 100, 1000, etc.). For example, scale_amount = 100 #' would scale down a value from 500,000 --> 5,000 and would report abundance in #' hundreds of fish (if "fish" was the unit_label). This scale will be reflected #' in the legend label if proportional is set to FALSE. -#' +#' #' Default: 1,000 -#' +#' #' @param proportional Set size of points relative to z when TRUE, point #' size are relative to one another while when set to FALSE, point size #' is relative to z -#' +#' #' Default: `TRUE` -#' +#' #' @param make_rda TRUE/FALSE; indicate whether to produce an .rda file containing #' a list with the figure/table, caption, and alternative text (if figure). If TRUE, #' the .rda will be exported to the folder indicated in the argument "rda_dir". -#' +#' #' Default: `FALSE` -#' +#' #' @param figures_dir The location of the folder containing the generated .rda files #' ("rda_files") that will be created if the argument `make_rda` = TRUE. -#' +#' #' Default: the working directory (`getwd()`) -#' +#' #' @returns A plot showing total abundance (or numbers) at age. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @seealso [convert_output()], [filter_data()], [process_data()], [plot_aa()], [export_kqs()], [insert_kqs()], [create_rda()] -#' +#' #' @export #' #' @examples diff --git a/R/plot_biomass.R b/R/plot_biomass.R index c3ba3bb4..7121eea8 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -2,7 +2,7 @@ #' #' @inheritParams plot_spawning_biomass #' @param unit_label units for biomass -#' +#' #' Default: "mt" #' @param ref_line A string specifying the type of reference you want to #' compare biomass to. The default `"msy"` looks for @@ -11,19 +11,19 @@ #' lower-case letters. However, you must use one of the options specified in the #' default list to ensure that the label on the figure looks correct #' regardless of how it is specified in `dat`. -#' +#' #' Default: "msy" -#' +#' #' Options: Including, but not limited to: "target", "MSY", "unfished" #' @returns A plot showing total biomass. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @seealso [convert_output()], [plot_timeseries()], [calculate_reference_point()], [reference_line()], [filter_data()], [process_data()], [export_kqs()], [insert_kqs()], [create_rda()] -#' +#' #' @export #' #' @examples @@ -113,7 +113,7 @@ plot_biomass <- function( ) } } - + # Process data for indexing/grouping # TODO: check and add into process_data step to summarize when theres >1 label processing <- process_data( @@ -121,12 +121,12 @@ plot_biomass <- function( group, facet ) - + # variable <- processing[[1]] prepared_data <- processing[[1]] group <- processing[[2]] if (!is.null(processing[[3]])) facet <- processing[[3]] - + plt <- plot_timeseries( dat = prepared_data, diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index c0933bf5..89a926c7 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -13,16 +13,16 @@ #' filtering when preparing data for the plot. #' #' Default: `TRUE` -#' +#' #' @returns A plot showing total biomass at age. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @seealso [convert_output()], [filter_data()], [process_data()], [plot_aa()], [export_kqs()], [insert_kqs()], [create_rda()] -#' +#' #' @export #' #' @examples diff --git a/R/plot_catch_comp.R b/R/plot_catch_comp.R index 0a900e48..f1bad7b2 100644 --- a/R/plot_catch_comp.R +++ b/R/plot_catch_comp.R @@ -2,28 +2,28 @@ #' #' @inheritParams plot_abundance_at_age #' @param unit_label indicate the name of the units of catch as to label the axis -#' +#' #' Default: "mt" -#' +#' #' @param scale_amount A number describing how much to scale down the catch at #' age. Please choose a value ranging from 1-1,000,000,000 (one billion) in orders #' of magnitude (e.g., 1, 10, 100, 1000, etc.). For example, scale_amount = 100 #' would scale down a value from 500,000 --> 5,000 and would report catch in #' hundreds of the 'unit_label'. This scale will be reflected #' in the legend label if proportional is set to FALSE. -#' +#' #' Default: 1 -#' +#' #' @param era A string naming the era of data. #' #' Default: "time" #' #' Options: "early", "time", "fore" (forecast), or NULL (all data) -#' +#' #' @param interactive A logical value indicating if the environment is interactive. #' #' Default: `FALSE` -#' +#' #' @param module (Optional) A string indicating the module_name found in `dat`. #' If selecting >1 module, place them in a vector like c("module1", "module2"). #' @@ -31,9 +31,9 @@ #' #' If the interactive and >1 module_name is found, user will select the #' module_name in the console. @seealso [filter_data()] -#' +#' #' @returns A plot showing catch or landings composition. -#' +#' #' @details This plot is made only when catch or landings are explicitly named #' in the output file. The current plot function does not combine all sources of #' catch. diff --git a/R/plot_fishing_mortality.R b/R/plot_fishing_mortality.R index 518a8e86..a86abb2e 100644 --- a/R/plot_fishing_mortality.R +++ b/R/plot_fishing_mortality.R @@ -3,14 +3,14 @@ #' @inheritParams plot_spawning_biomass #' #' @returns A plot showing fishing mortality over time. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @seealso [convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [reference_line()], [export_kqs()], [insert_kqs()], [create_rda()] -#' +#' #' @export #' #' @examples @@ -85,13 +85,12 @@ plot_fishing_mortality <- function( ### Make RDA ---- if (make_rda) { - F.min <- min(prepared_data$estimate) |> round(digits = 3) F.max <- max(prepared_data$estimate) |> round(digits = 3) - + export_kqs(F.min, F.max) insert_kqs(F.min, F.max) - + F.ref.pt <- as.character(ref_line) F.start.year <- min(prepared_data$year) F.end.year <- max(prepared_data$year) diff --git a/R/plot_indices.R b/R/plot_indices.R index e9932ae9..a2a61d49 100644 --- a/R/plot_indices.R +++ b/R/plot_indices.R @@ -14,14 +14,14 @@ #' #' Default: NULL #' @returns A plot showing the expected and predicted indices. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @seealso [convert_output()], [filter_data()], [process_data()], [plot_obsvpred()], [export_kqs()], [insert_kqs()], [create_rda()] -#' +#' #' @export #' #' @examples @@ -74,7 +74,7 @@ plot_indices <- function( prepared_data <- prepared_data |> dplyr::filter(fleet %in% focus) } - + processed_data <- process_data( dat = prepared_data, group = group, @@ -120,7 +120,7 @@ plot_indices <- function( facet_formula <- stats::reformulate(facet) plt <- plt + ggplot2::facet_wrap(facet_formula, scales = "free") } - + ### Make RDA ---- if (make_rda) { # Obtain relevant key quantities for captions/alt text diff --git a/R/plot_landings.R b/R/plot_landings.R index b2d20da4..2e975fba 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -3,14 +3,14 @@ #' @inheritParams plot_spawning_biomass #' #' @returns A plot showing cumulative landings over time. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @seealso [convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()] -#' +#' #' @export #' #' @examples @@ -48,7 +48,7 @@ plot_landings <- function( cli::cli_alert_info("Unit label was not changed. Setting unit_label to 'lbs'.") unit_label <- "lbs" } - + # Units landings_label <- label_magnitude( label = "Landings", diff --git a/R/plot_natural_mortality.R b/R/plot_natural_mortality.R index 6bb1e6af..de85727c 100644 --- a/R/plot_natural_mortality.R +++ b/R/plot_natural_mortality.R @@ -3,14 +3,14 @@ #' @inheritParams plot_spawning_biomass #' #' @returns A plot showing natural mortality at age. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @seealso [convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()] -#' +#' #' @export #' #' @examples diff --git a/R/plot_recruitment.R b/R/plot_recruitment.R index 712f275f..c2658450 100644 --- a/R/plot_recruitment.R +++ b/R/plot_recruitment.R @@ -6,14 +6,14 @@ #' Default: "mt" #' #' @returns A plot showing recruitment over time. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' -#' @seealso [convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()] -#' +#' +#' @seealso [convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()] +#' #' @export #' #' @examples diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index e07f1cbf..20021786 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -19,7 +19,7 @@ #' #' Default: NULL #' Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL -#' +#' #' @param facet A string or vector of strings of a column name. #' #' Default: NULL @@ -39,7 +39,7 @@ #' Default: "mt" #' @param lbs A logical value indicating whether to convert the y-axis values from #' kilograms to pounds. The default units match the default in the -#' unit_label argument - 'mt'. +#' unit_label argument - 'mt'. #' #' Default: `FALSE` #' @param module (Optional) A string indicating the module_name found in `dat`. @@ -70,14 +70,14 @@ #' #' Default: `FALSE` #' @param ... Arguments called from \link[ggplot2]{geom_line} or \link[ggplot2]{geom_point} -#' +#' #' @return A plot showing spawning biomass over time. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @note #' All plotting functions automatically recognize indexing variables and will #' use them in groupings and/or facetting. @seealso [process_data()]. @@ -125,7 +125,7 @@ plot_spawning_biomass <- function( cli::cli_alert_info("Unit label was not changed. Setting unit_label to 'lbs'.") unit_label <- "lbs" } - + # TODO: Fix the unit label if scaling. Maybe this is up to the user to do if # they want something scaled then they have to supply a better unit name # or we create a helper function to do this. @@ -137,10 +137,10 @@ plot_spawning_biomass <- function( label = "Spawning Biomass", unit_label = unit_label, scale_amount = dplyr::if_else( - lbs, - ifelse(unit_label %in% c("mt", "mts", "metric tons", "metric ton"), 1000, 1) * scale_amount, + lbs, + ifelse(unit_label %in% c("mt", "mts", "metric tons", "metric ton"), 1000, 1) * scale_amount, scale_amount - ), + ), legend = TRUE ) } @@ -159,24 +159,24 @@ plot_spawning_biomass <- function( # Filter data for spawning biomass prepared_data <- filter_data( - dat = dat, - label_name = ifelse(relative, glue::glue("spawning_biomass_spawning_biomass_{ref_line}|spawning_biomass_ratio"), "^spawning_biomass$"), - geom = geom, - era = era, - group = group, - facet = facet, - module = module, - scale_amount = scale_amount, - interactive = interactive - ) - + dat = dat, + label_name = ifelse(relative, glue::glue("spawning_biomass_spawning_biomass_{ref_line}|spawning_biomass_ratio"), "^spawning_biomass$"), + geom = geom, + era = era, + group = group, + facet = facet, + module = module, + scale_amount = scale_amount, + interactive = interactive + ) + if (relative) { if (nrow(prepared_data) == 0) { cli::cli_abort("No data found for relative biomass. Please check that your data contains a label for 'biomass_biomass_unfished'.") stop() } - } - + } + # process the data for grouping processing <- process_data( dat = prepared_data, @@ -189,7 +189,7 @@ plot_spawning_biomass <- function( plot_data <- processing[[1]] group <- processing[[2]] if (!is.null(processing[[3]])) facet <- processing[[3]] - + # Override grouping variable when there is only NA's if (!is.null(group)) { if (group %notin% colnames(plot_data)) group <- NULL @@ -238,7 +238,7 @@ plot_spawning_biomass <- function( ) + theme_noaa() } } - + ### Make RDA ---- if (make_rda) { if (relative) { diff --git a/R/plot_stock_recruitment.R b/R/plot_stock_recruitment.R index 23e6cc33..f4c5d2c6 100644 --- a/R/plot_stock_recruitment.R +++ b/R/plot_stock_recruitment.R @@ -11,21 +11,21 @@ #' @param spawning_biomass_label Units for spawning biomass #' #' Default: "mt" -#' +#' #' @param recruitment_label units for recruitment #' #' Default: "mt" #' #' @returns A plot showing the stock recruitment relationship. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a `ggplot2` object or export an .rda object #' containing associated caption and alternative text for the figure. -#' +#' #' @seealso [convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()] -#' -#' +#' +#' #' @export #' #' @examples @@ -64,15 +64,15 @@ plot_stock_recruitment <- function( # filter out rec devs if in data !grepl("deviations", label) ) - + process_rec <- process_data( recruitment ) - + rec_proc <- process_rec[[1]] group <- process_rec[[2]] facet <- process_rec[[3]] - + if (length(unique(recruitment$label)) > 1) { rec_proc <- rec_proc |> tidyr::pivot_wider( @@ -83,7 +83,7 @@ plot_stock_recruitment <- function( # rename columns to remove "estimate" colnames(rec_proc) <- gsub("estimate_", "", colnames(rec_proc)) } else { - rec_proc <- rec_proc|> + rec_proc <- rec_proc |> dplyr::rename( predicted_recruitment = estimate, lower_predicted_recruitment = estimate_lower, @@ -109,19 +109,19 @@ plot_stock_recruitment <- function( ) |> dplyr::filter(!is.na(year)) - process_sb <- process_data( - sb - ) - sb_proc <- process_sb[[1]] |> - dplyr::rename( - spawning_biomass = estimate, - lower_spawning_biomass = estimate_lower, - upper_spawning_biomass = estimate_upper - ) |> - dplyr::select(-label) - # group <- process_sb[[2]] - # facet <- process_sb[[3]] - + process_sb <- process_data( + sb + ) + sb_proc <- process_sb[[1]] |> + dplyr::rename( + spawning_biomass = estimate, + lower_spawning_biomass = estimate_lower, + upper_spawning_biomass = estimate_upper + ) |> + dplyr::select(-label) + # group <- process_sb[[2]] + # facet <- process_sb[[3]] + # Merge recruitment and spawning biomass data sr <- dplyr::left_join(sb_proc, rec_proc, by = c("year", "model", "group_var")) diff --git a/R/process_data.R b/R/process_data.R index b4499283..ec8770fb 100644 --- a/R/process_data.R +++ b/R/process_data.R @@ -20,7 +20,7 @@ #' Default: NULL #' @param lbs A logical value indicating whether to convert the y-axis values from #' kilograms to pounds. The default units match the default in the -#' unit_label argument - 'metric tons'. +#' unit_label argument - 'metric tons'. #' #' Default: `FALSE` #' @param method A string describing the method of summarizing data when group @@ -39,11 +39,11 @@ #' \item{facet}{A string or vector of strings identifying the faceting #' variable(s) of the data. If NULL, no faceting variable is identified. Any #' identified indexed variables found in this function will be added to facet.} -#' +#' #' @details Automatically detects potential grouping and faceting data from a #' dataframe output from \link[stockplotr]{filter_data}. -#' -#' +#' +#' #' @export #' #' @examples { @@ -232,7 +232,7 @@ process_data <- function( } else { group <- valid_vars[1] } - + # Remove group from index_variables so no repeats if (length(valid_vars) > 0) { index_variables <- index_variables[-grep(valid_vars[1], index_variables)] @@ -337,7 +337,7 @@ process_data <- function( group <- NULL } } - + # Ensure that index_variables -- group or facets are non-numeric to be plotted accurately data <- data |> dplyr::mutate( @@ -346,14 +346,14 @@ process_data <- function( as.character ) ) - + if (lbs) { data <- data |> dplyr::mutate( # multiple by conversion from kg to lbs -- default then becomes thousands of lbs estimate = (estimate * 2.20462), - estimate_lower = NA_real_, #(estimate_lower * 2.20462), - estimate_upper = NA_real_, #(estimate_upper * 2.20462) + estimate_lower = NA_real_, # (estimate_lower * 2.20462), + estimate_upper = NA_real_, # (estimate_upper * 2.20462) ) } @@ -372,12 +372,12 @@ process_data <- function( #' #' @inheritParams process_data #' @param label A string or vector of strings identifying the label values to filter the data. -#' +#' #' Default: NULL #' #' @returns A dataframe of processed data ready for formatting into a table. #' @details Input is an object created with \link[stockplotr]{filter_data}. -#' +#' #' @export #' #' @examples { diff --git a/R/save_all_plots.R b/R/save_all_plots.R index 10249c6e..8db8bd57 100644 --- a/R/save_all_plots.R +++ b/R/save_all_plots.R @@ -7,18 +7,18 @@ #' the recruitment quantities shown on the y axis. For example, #' recruitment_scale_amount = 100 would scale down a value from 500,000 --> #' 5,000. This scale will be reflected in the y axis label. -#' +#' #' Default: 1 -#' +#' #' @param recruitment_unit_label Units for recruitment -#' +#' #' Default: "mt" -#' +#' #' @param figures_tables_dir The location of the folder containing #' figures and tables ("figures" and "tables"). -#' +#' #' Default: the working directory (`getwd()`) -#' +#' #' @param ref_line A string specifying the type of reference you want to #' compare biomass to. The default is `"msy"`, which looks for #' `"biomass_msy"` in the `"label"` column of `dat`. The actual @@ -28,87 +28,87 @@ #' regardless of how it is specified in `dat`. Other possibilities may include #' "target", "MSY", and "unfished". When the reference cannot be found, #' indicate the reference line in the form c("label" = value). -#' +#' #' Default: "msy" -#' +#' #' Options: Including, but not limited to: "target", "MSY", "unfished" -#' +#' #' @param biomass_scale_amount A number describing how much to scale down the #' biomass quantities shown on the y axis. See `recruitment_scale_amount`. -#' +#' #' Default: 1 -#' +#' #' @param landings_unit_label Units for landings -#' +#' #' Default: "mt" -#' +#' #' @param biomass_unit_label Units for biomass #' #' Default: "mt" -#' +#' #' @param spawning_biomass_label Units for spawning biomass -#' +#' #' Default: "mt" -#' +#' #' @param spawning_biomass_scale_amount A number describing how much to scale down the #' spawning biomass quantities shown on the y axis. See `recruitment_scale_amount`. -#' +#' #' Default: 1 -#' +#' #' @param ref_line_sb Identical definition as `ref_line`, but this argument is #' applied to plot_spawning_biomass. -#' +#' #' Default: "msy" -#' +#' #' Options: Including, but not limited to: "target", "MSY", "unfished" -#' +#' #' @param abundance_at_age_scale_amount A number describing how much to scale down the #' abundance quantities shown via bubble size. See `recruitment_scale_amount`. -#' +#' #' Default: 1 -#' +#' #' @param abundance_at_age_unit_label Abbreviated units for abundance at age -#' +#' #' Default: "fish" -#' +#' #' @param biomass_at_age_scale_amount A number describing how much to scale down the #' biomass quantities shown via bubble size. See `recruitment_scale_amount`. -#' +#' #' Default: 1 -#' +#' #' @param biomass_at_age_unit_label Abbreviated units for biomass at age -#' -#' Default: "mt" -#' +#' +#' Default: "mt" +#' #' @param indices_unit_label Units for index of abundance/CPUE -#' +#' #' Default: "" -#' +#' #' @param biomass_unit_label Abbreviated units for biomass -#' +#' #' Default: "mt" -#' +#' #' @param catch_unit_label Abbreviated units for catch -#' +#' #' Default: "mt" -#' +#' #' @param catch_scale_amount A number describing how much to scale down the #' catch quantities shown via bubble size. See `recruitment_scale_amount`. -#' +#' #' Default: 1 -#' +#' #' @param landings_unit_label Units for landings -#' +#' #' Default: "mt" -#' +#' #' @param proportional T/F to scale size of bubble plots -#' +#' #' Default: `TRUE` #' #' @returns Rda files for each figure/table. -#' +#' #' @seealso [convert_output()], [create_rda()] -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' diff --git a/R/stockplotr-package.R b/R/stockplotr-package.R index 957c0bf9..d7ea398f 100644 --- a/R/stockplotr-package.R +++ b/R/stockplotr-package.R @@ -17,7 +17,7 @@ globvar <- c( "plot_data", "quantile", "rda_dir", "reorder", "total_estimate", "zvar", "filter_data", "Component", "age_bins", "alt_label", "final_df", "init", "keyword", "len_bins", "like", "match_key", "morph", "nsim", "output", "output_order", "parm_stdev", "seas", - "sexes", "subseas", "unique_count", "value", "yr", "fleet_names", "across", + "sexes", "subseas", "unique_count", "value", "yr", "fleet_names", "across", "everything", "fleet_name", "name", "value_new", "y", ".", # Rceattle conout terms "n", "observation", "selectivity_block", "log_sd", "fleet_code", diff --git a/R/table_landings.R b/R/table_landings.R index 95570d3c..d75e3a69 100644 --- a/R/table_landings.R +++ b/R/table_landings.R @@ -2,7 +2,7 @@ #' #' @inheritParams plot_recruitment #' @param unit_label Abbreviated units of landings -#' +#' #' Default: "mt" #' @param group A string of a single column that groups the data. #' @@ -18,25 +18,25 @@ #' Options: "sum" or "mean" #' @param tables_dir The location of the folder containing the generated table #' rda files ("tables") that will be created if the argument `make_rda` = TRUE. -#' +#' #' Default: the working directory (`getwd()`) #' @param label The label that will be chosen from the input file. If unspecified, #' the function will search the "label" column and use the first matching label #' in this ordered list: "landings_weight", "landings_numbers", "landings_expected", #' "landings_predicted", "landings". -#' +#' #' Default: NULL #' #' @returns A table ready of landed catch by fleet and year. -#' +#' #' @details The input is from an assessment model output file #' translated to a standardized output (\link[stockplotr]{convert_output}). #' There are options to return a [gt::gt()] object or export an rda object #' containing a gt-based table, caption, and LaTeX-based table. -#' +#' #' @seealso [convert_output()], [filter_data()], [process_table()], [export_kqs()], [insert_kqs()], [create_rda()] #' @export -#' +#' #' @examples #' table_landings(stockplotr::example_data) #' diff --git a/R/utils.R b/R/utils.R index 6ba1da95..08cb3b82 100644 --- a/R/utils.R +++ b/R/utils.R @@ -198,14 +198,14 @@ SS3_extract_fleet <- function(dat, vers) { # input_list = unlisted object from model output expand_element <- function(input_list, fleet_names = "Pollock") { - # Use map_dfr to iterate over each element of the list # .id = "origin_var" keeps track of which list element the data came from purrr::imap_dfr(input_list, function(x, name) { - # Skip empty/null elements immediately - if (length(x) == 0 || is.null(x)) return(NULL) - + if (length(x) == 0 || is.null(x)) { + return(NULL) + } + # Standardize current element 'x' to a Long Data Frame if (!is.null(dim(x)) && length(dim(x)) > 1) { # Handles Arrays/Matrices @@ -225,25 +225,25 @@ expand_element <- function(input_list, fleet_names = "Pollock") { )) |> dplyr::select(-dim_info) } - + # Process the labels df |> dplyr::mutate( label_init = as.character(label_init), - + # Pull parameter name label = dplyr::case_when( stringr::str_extract(label_init, "^[^\\.]+") == "rec_pars" ~ stringr::str_extract(label_init, "[^\\.]+$"), TRUE ~ stringr::str_extract(label_init, "^[^\\.]+") - ), - + ), + # Extract Age age = dplyr::case_when( - grepl("age", label_init, ignore.case = TRUE) ~ + grepl("age", label_init, ignore.case = TRUE) ~ as.numeric(stringr::str_extract(label_init, "(?<=\\.[Aa]ge)[0-9]+(?=\\.|$)")), TRUE ~ NA_real_ ), - + # Extract Sex sex = dplyr::case_when( grepl("Sex.combined|combined", label_init, ignore.case = TRUE) ~ "combined", @@ -251,16 +251,16 @@ expand_element <- function(input_list, fleet_names = "Pollock") { grepl("male", label_init, ignore.case = TRUE) ~ "male", # check havent seen example of this! TRUE ~ NA_character_ ), - + # Extract Year (4 digits) year = dplyr::case_when( grepl("[0-9]{4}", label_init) ~ as.numeric(stringr::str_extract(label_init, "[0-9]{4}")), TRUE ~ NA_real_ ), - + # Extract Fleet fleet = dplyr::case_when( - grepl(paste0(fleet_names, collapse = "|"), label_init) ~ + grepl(paste0(fleet_names, collapse = "|"), label_init) ~ stringr::str_extract(label_init, paste0(fleet_names, collapse = "|")), TRUE ~ NA_character_ ) @@ -270,4 +270,3 @@ expand_element <- function(input_list, fleet_names = "Pollock") { dplyr::select(-label_init) }) } - diff --git a/R/utils_plot.R b/R/utils_plot.R index e3a3c5f8..83a251b4 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -31,10 +31,10 @@ #' #' Default: NULL #' Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL -#' +#' #' @param facet a string or vector of strings of a column that facets the data #' (e.g. "year", "area", etc.) -#' +#' #' Default: NULL #' @param ... inherited arguments from internal functions from ggplot2::geom_xx #' @@ -43,7 +43,7 @@ #' @details The user can create a line, point, or area plot, where the x-axis is #' year and y can vary for any time series quantity. Currently, grouping is #' restricted to one group where faceting can be any number of facets. -#' +#' #' @export #' #' @examples @@ -237,7 +237,7 @@ plot_timeseries <- function( #' #' @inheritParams plot_timeseries #' @param hline indicate true or false to place a horizontal line at 1 -#' +#' #' Default: `TRUE` #' @param ... inherited arguments from internal functions from ggplot2::geom_xx #' @@ -308,33 +308,33 @@ plot_error <- function( #' #' @inheritParams plot_timeseries #' @param y a string of the column name of data used to plot on the y-axis -#' +#' #' Default: "age" #' @param z a string of the column name of data used to control the size of the #' bubbles -#' +#' #' Default: "estimate" #' @param label a string of the label for the size of the bubbles -#' +#' #' Default: "Abundance" -#' +#' #' @param xlab a string of the x-axis label -#' +#' #' Default: "Year" #' @param ylab a string of the y-axis label -#' +#' #' Default: "Age" #' @param facet a string or vector of strings of a column that facets the data. -#' It is not recommended to include more than one facet due to the complexity +#' It is not recommended to include more than one facet due to the complexity #' of the plot. -#' +#' #' Default: NULL -#' +#' #' Options: Including, but not limited to: "sex", "area", "fleet" #' @param proportional Set size of points relative to z when TRUE, point #' size are relative to one another while when set to FALSE, point size #' is relative to z -#' +#' #' Default: `TRUE` #' @param ... inherited arguments from internal functions from #' \link[ggplot2]{geom_point} @@ -530,7 +530,7 @@ cohort_line <- function( #' @param label_name string of the name of the quantity that users want to #' extract the reference point from #' @param reference string of the reference point -#' +#' #' Options: Including, but not limited to: "msy", "unfished", "target" #' #' @returns A ggplot2 geom_hline object for a reference point that can be added @@ -953,7 +953,6 @@ calculate_reference_point <- function( } else { ref_line_val } - } #------------------------------------------------------------------------------ @@ -1019,7 +1018,7 @@ check_grouping <- function(dat) { #' #' @inheritParams plot_timeseries #' @param observed_label a string of the label used to filter the observed data -#' +#' #' Default: "observed" #' @param predicted_label a string of the label used to filter the predicted data #' Default: "predicted" diff --git a/R/utils_rda.R b/R/utils_rda.R index 5072debb..a2125ecc 100644 --- a/R/utils_rda.R +++ b/R/utils_rda.R @@ -56,7 +56,7 @@ fill_in_kqs <- function(df, ...) { #' added next to the names of the key quantities specified as ellipsis #' arguments. File is saved as "key_quantities.csv" to the working directory. #' @seealso [fill_in_kqs()], [insert_kqs()] -#' +#' #' @examples \dontrun{ #' export_kqs( #' F.min, @@ -96,7 +96,7 @@ export_kqs <- function(...) { #' and alternative text for figures and tables, with key quantities inserted #' into the "captions_alt_text_template.csv" template's placeholders. #' @seealso [fill_in_kqs()], [export_kqs()] -#' +#' #' @examples \dontrun{ #' insert_kqs( #' F.min, @@ -197,29 +197,29 @@ insert_kqs <- function(...) { #' @param dat Data frame containing data which will fill in captions and #' alternative text for the object #' @param dir Directory to where the rda will be saved -#' +#' #' Default: the working directory (`getwd()`) -#' +#' #' @param year Assessment year -#' +#' #' Default: the current year -#' +#' #' @param ref_line Reference line value -#' +#' #' Default: "msy" -#' +#' #' Options: Including, but not limited to: "msy", "target", "unfished" -#' +#' #' @param scale_amount A number describing how much to scale down the quantities #' shown on the y axis. For example, scale_amount = 100 would scale down a value #' from 500,000 --> 5,000. This scale will be reflected in the y axis label. -#' +#' #' Default: 1 -#' +#' #' @param unit_label A string containing a unit label for the y-axis -#' +#' #' Default: "mt" -#' +#' #' @param table_df The data frame that the table will be made into for purposes #' of exporting a latex formatted table. #' @@ -515,13 +515,13 @@ create_rda <- function( #' @param topic_label A string that describes a figure or table's label. These #' labels are found in the "label" column of the "captions_alt_text.csv" file #' and are used to link the figure or table with its caption/alt text. -#' +#' #' Default: NULL -#' +#' #' @param fig_or_table A string describing whether the plot is a figure or table. -#' +#' #' Default: NULL -#' +#' #' @param dir The directory containing the "captions_alt_text.csv" file. #' #' Default: the working directory (`getwd()`) @@ -589,42 +589,42 @@ extract_caps_alttext <- function(topic_label = NULL, #' Typically used after stockplotr::extract_caps_alttext(). #' #' @param object The final figure (ggplot) or table (flextable) object. -#' +#' #' Default: NULL -#' +#' #' @param caps_alttext The object containing a figure's caption and alternative #' text, in a list, or a table's caption, likely generated with #' stockplotr::extract_caps_alttext(). -#' +#' #' Default: NULL -#' +#' #' @param figures_tables_dir If the user has already created folders containing #' figures and tables ("figures" and "tables"), figures_tables_dir represents #' the location of these folders. Otherwise, these two folders will be created #' automatically, then used to store the exported rda files. -#' +#' #' Default: NULL -#' +#' #' @param topic_label A string that describes a figure or table's label. These #' labels are found in the "label" column of the "captions_alt_text.csv" file #' and are used to link the figure or table with its caption/alt text. -#' +#' #' Default: NULL -#' +#' #' @param fig_or_table A string describing whether the plot is a figure or table. -#' +#' #' Default: NULL -#' +#' #' Options: "figure", "table" -#' +#' #' @param latex_table The object containing a LaTeX-based table. -#' +#' #' Default: NULL -#' +#' #' @returns An rda file with a figure's ggplot, caption, and alternative text, or #' a table's gt-based table, caption, and LaTeX-based table. #' @seealso [create_rda()], [extract_caps_alttext()] -#' +#' #' @export #' #' @examples diff --git a/man/convert_output.Rd b/man/convert_output.Rd index ce7974db..26efaf8b 100644 --- a/man/convert_output.Rd +++ b/man/convert_output.Rd @@ -16,10 +16,10 @@ Default: NULL Options: "ss3", "bam", "fims", "rceattle"} \item{fleet_names}{Names of fleets in the assessment model as -shortened in the output file. If fleet names are not properly read, then -indicate the fleets names as an acronym in a vector + shortened in the output file. If fleet names are not properly read, then + indicate the fleets names as an acronym in a vector -Default: NULL} + Default: NULL} \item{save_dir}{File path to save the converted output file. @@ -34,8 +34,8 @@ A reformatted and standardized version of assessment model results Format stock assessment output files to a standardized format. } \details{ -The resulting object is simply a transformed and machine readable -version of a model output file. Converted data frame is always returned. +The resulting object is simply a transformed and machine readable +version of a model output file. Converted data frame is always returned. It will also be saved if save_dir is not NULL. } \examples{ diff --git a/man/example_data.Rd b/man/example_data.Rd index 90e120b4..3cbf0892 100644 --- a/man/example_data.Rd +++ b/man/example_data.Rd @@ -46,7 +46,7 @@ A tibble with 591109 rows and 33 variables: example_data } \description{ -Included data set that represents a Report.sso file converted using +Included data set that represents a Report.sso file converted using convert_output(). This example is from the 2022 Petrale sole stock assessment. } \keyword{datasets} diff --git a/man/plot_aa.Rd b/man/plot_aa.Rd index 178e7611..054e7136 100644 --- a/man/plot_aa.Rd +++ b/man/plot_aa.Rd @@ -47,7 +47,7 @@ Default: "Year"} Default: "Age"} \item{facet}{a string or vector of strings of a column that facets the data. -It is not recommended to include more than one facet due to the complexity +It is not recommended to include more than one facet due to the complexity of the plot. Default: NULL diff --git a/man/plot_biomass.Rd b/man/plot_biomass.Rd index f4276339..2116f92c 100644 --- a/man/plot_biomass.Rd +++ b/man/plot_biomass.Rd @@ -52,7 +52,7 @@ Default: NULL} lower-case letters. However, you must use one of the options specified in the default list to ensure that the label on the figure looks correct regardless of how it is specified in `dat`. - + Default: "msy" Options: Including, but not limited to: "target", "MSY", "unfished"} diff --git a/man/plot_landings.Rd b/man/plot_landings.Rd index edcb43de..b978e072 100644 --- a/man/plot_landings.Rd +++ b/man/plot_landings.Rd @@ -50,7 +50,7 @@ Default: NULL} \item{lbs}{A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the -unit_label argument - 'mt'. +unit_label argument - 'mt'. Default: `FALSE`} diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index c5a53c69..271b5a09 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -65,7 +65,7 @@ Options: "early", "time", "fore" (forecast), or NULL (all data)} \item{lbs}{A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the -unit_label argument - 'mt'. +unit_label argument - 'mt'. Default: `FALSE`} diff --git a/man/process_data.Rd b/man/process_data.Rd index e37c57a1..e5a2d8a5 100644 --- a/man/process_data.Rd +++ b/man/process_data.Rd @@ -26,7 +26,7 @@ Default: NULL} \item{lbs}{A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the -unit_label argument - 'metric tons'. +unit_label argument - 'metric tons'. Default: `FALSE`} diff --git a/man/reference_line.Rd b/man/reference_line.Rd index 6f0b390d..d9ad74fa 100644 --- a/man/reference_line.Rd +++ b/man/reference_line.Rd @@ -24,7 +24,7 @@ Default: 1} \item{lbs}{A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the -unit_label argument - 'mt'. +unit_label argument - 'mt'. Default: `FALSE`} } diff --git a/tests/testthat/test-plot_biomass.R b/tests/testthat/test-plot_biomass.R index b9e87194..f9b40089 100644 --- a/tests/testthat/test-plot_biomass.R +++ b/tests/testthat/test-plot_biomass.R @@ -7,7 +7,7 @@ load(file.path( # Below is now moot bc relative is coming from model results # Make another sample dataset for testing relative # n <- 448 -# +# # sim_df <- data.frame( # label = "biomass", # estimate = rlnorm(n, meanlog = 6.2, sdlog = 1.6), diff --git a/tests/testthat/test-plot_spawning_biomass.R b/tests/testthat/test-plot_spawning_biomass.R index 8dc1d811..267c2094 100644 --- a/tests/testthat/test-plot_spawning_biomass.R +++ b/tests/testthat/test-plot_spawning_biomass.R @@ -59,4 +59,3 @@ test_that("rda file made when indicated", { file.remove(fs::path(getwd(), "key_quantities.csv")) unlink(fs::path(getwd(), "figures"), recursive = T) }) - diff --git a/tests/testthat/test-save_all_plots.R b/tests/testthat/test-save_all_plots.R index ee5bc68c..1b268f39 100644 --- a/tests/testthat/test-save_all_plots.R +++ b/tests/testthat/test-save_all_plots.R @@ -41,15 +41,15 @@ test_that("save_all_plots works when all figures/tables are plotted", { ) # expect that the tables are all created with expected names - tab_base_temp_files <- c( + 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 - ) + # "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"))