From d77571be5944021bea95f8a7a9dcd086189f73fe Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Tue, 19 May 2026 10:42:35 -0400 Subject: [PATCH 1/3] add option to change number of digits in rounding and scale numbers in table --- R/table_landings.R | 19 ++++++++++++++++--- R/utils_table.R | 8 ++++---- man/table_landings.Rd | 11 +++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/R/table_landings.R b/R/table_landings.R index 52d14eac..473429a7 100644 --- a/R/table_landings.R +++ b/R/table_landings.R @@ -6,6 +6,10 @@ #' want to just summarize the data across all factors, set group = "none". #' @param method A string describing the method of summarizing data when group #' is set to "none". Options are "sum" or "mean". Default is "sum". +#' @param digits Numeric value indicating the number of digits values in the +#' table will be rounded to. +#' +#' Default: 2 #' @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. #' @param label The label that will be chosen from the input file. If unspecified, @@ -40,9 +44,18 @@ table_landings <- function( method = "sum", module = NULL, label = NULL, + digits = 2, + scale_amount = 1, make_rda = FALSE, tables_dir = getwd() ) { + # set unit label if scaled + unit_label <- label_magnitude( + label = "", + unit_label = unit_label, + scale_amount = scale_amount + ) + # TODO: do group and facet need to be uncommented and updated? # Filter data for landings prepared_data <- filter_data( @@ -51,11 +64,11 @@ table_landings <- function( geom = "line", era = era, module = module, - scale_amount = 1, + scale_amount = scale_amount, interactive = interactive ) |> - dplyr::mutate(estimate = round(as.numeric(estimate), digits = 0)) |> - dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = 2)) + dplyr::mutate(estimate = round(as.numeric(estimate), digits = digits)) |> + dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = digits)) # Add check if there is any data if (nrow(prepared_data) == 0) { diff --git a/R/utils_table.R b/R/utils_table.R index c7fe4ffe..c728912e 100644 --- a/R/utils_table.R +++ b/R/utils_table.R @@ -219,8 +219,8 @@ merge_error <- function(table_data, uncert_lab, fleets, label, unit_label) { label_cols_final <- c( ifelse( id_uncert == "uncertainty", - paste0(stringr::str_to_title(label), " (", unit_label, ")"), - paste0(stringr::str_to_title(label), " (", unit_label, ") (", id_uncert, ")") + paste0(stringr::str_to_title(label), " ", unit_label), + paste0(stringr::str_to_title(label), " ", unit_label, " (", id_uncert, ")") ), id_uncert ) @@ -235,10 +235,10 @@ merge_error <- function(table_data, uncert_lab, fleets, label, unit_label) { uncert_lab, " ", label_lab ) if (uncert_lab == "uncertainty" || length(uncert_lab) == 0) { - label_cols_final <- c(paste0(label_lab, " (", unit_label, ")"), uncert_lab) + label_cols_final <- c(paste0(label_lab, " ", unit_label), uncert_lab) } else { label_cols_final <- c( - paste0(label_lab, " (", unit_label, ") (", uncert_lab, ")"), + paste0(label_lab, " ", unit_label, " (", uncert_lab, ")"), id_uncert_col ) } diff --git a/man/table_landings.Rd b/man/table_landings.Rd index 1e07bc63..93c0ad3c 100644 --- a/man/table_landings.Rd +++ b/man/table_landings.Rd @@ -13,6 +13,8 @@ table_landings( method = "sum", module = NULL, label = NULL, + digits = 2, + scale_amount = 1, make_rda = FALSE, tables_dir = getwd() ) @@ -54,6 +56,15 @@ 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".} +\item{digits}{Numeric value indicating the number of digits values in the +table will be rounded to. + +Default: 2} + +\item{scale_amount}{A number to scale the y-axis values. + +Default: 1} + \item{make_rda}{A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an `rda` object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir". From c4687405d98275462cb36cd61dbf7907e5b982bb Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Tue, 19 May 2026 10:57:23 -0400 Subject: [PATCH 2/3] update DESCRIPTION with version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 57273285..b36087a0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: stockplotr Title: Tables and Figures for Stock Assessments -Version: 0.11.0 +Version: 0.12.0 Authors@R: c( person("Samantha", "Schiano", , "samantha.schiano@noaa.gov", role = c("aut", "cre"), comment = c(ORCID = "0009-0003-3744-6428")), From 80e6c50550942044662329370639151fa9f4c0a0 Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Tue, 19 May 2026 15:50:32 -0400 Subject: [PATCH 3/3] change wording on digitd man --- R/table_landings.R | 3 +-- man/table_landings.Rd | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/R/table_landings.R b/R/table_landings.R index 473429a7..f69ba25f 100644 --- a/R/table_landings.R +++ b/R/table_landings.R @@ -6,8 +6,7 @@ #' want to just summarize the data across all factors, set group = "none". #' @param method A string describing the method of summarizing data when group #' is set to "none". Options are "sum" or "mean". Default is "sum". -#' @param digits Numeric value indicating the number of digits values in the -#' table will be rounded to. +#' @param digits Numeric value indicating the number of rounding digits. #' #' Default: 2 #' @param tables_dir The location of the folder containing the generated table diff --git a/man/table_landings.Rd b/man/table_landings.Rd index 93c0ad3c..48f8cf71 100644 --- a/man/table_landings.Rd +++ b/man/table_landings.Rd @@ -56,8 +56,7 @@ 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".} -\item{digits}{Numeric value indicating the number of digits values in the -table will be rounded to. +\item{digits}{Numeric value indicating the number of rounding digits. Default: 2}