From 9721ff38b78d8023726bc6d68178bb832008d0af Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Fri, 29 May 2026 14:31:03 -0400 Subject: [PATCH 1/4] expand checks when extracting data table in module selection to be based on blank row OR relative to the next place report is mentioned --- R/utils.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/R/utils.R b/R/utils.R index 6ba1da95..8ae55ab5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -102,6 +102,18 @@ SS3_extract_df <- function(dat, label) { # Find the first blank row that appears after the start_row end_row <- next_blank_rows[which(next_blank_rows > start_row)[1]] + + # Add check to determine if after next blank row contains a new report + # if not --> then use reference to next report as value + # Find all report: rows + report_rows <- which(apply(dat, 1, function(row) any(grepl("report:", row)))) + if (!any(grepl("report:", dat[end_row + 2]))) { + # ID where the next report row is + next_report_row <- report_rows[which(report_rows > start_row)[1]] + # Go back to the actual end row of target label + end_row <- ifelse(grep(next_report_row - 1, next_blank_rows), next_report_row - 2, next_report_row - 1) + } + if (is.na(end_row) || length(end_row) == 0) { end_row <- nrow(dat) } From 349de1681b8b5ac561046e5f3cc7d7033ecbc777 Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Fri, 29 May 2026 14:31:32 -0400 Subject: [PATCH 2/4] replace any blank placeholders from SS3 such as - or _ with NA --- R/convert_output.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/convert_output.R b/R/convert_output.R index e4efb507..58ae9ec7 100644 --- a/R/convert_output.R +++ b/R/convert_output.R @@ -553,6 +553,11 @@ convert_output <- function( label = dplyr::case_when( label == "f" ~ "fishing_mortality", TRUE ~ label + ), + estimate = dplyr::if_else( + grepl("-|_", estimate), + NA, + estimate ) ) @@ -569,12 +574,7 @@ convert_output <- function( ) colnames(df5) <- tolower(names(df5)) } - # param_df <- df5 - # if (ncol(out_new) < ncol(df5)){ - # warning(paste0("Transformed data frame for ", parm_sel, " has more columns than default.")) - # } else if (ncol(out_new) > ncol(df5)){ - # warning(paste0("Transformed data frame for ", parm_sel, " has less columns than default.")) - # } + if ("seas" %in% colnames(df5)) df5 <- dplyr::rename(df5, season = seas) if ("subseas" %in% colnames(df5)) df5 <- dplyr::rename(df5, subseason = subseas) From 872294c28fe295e9883de745bd5788ab6b4456a0 Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Fri, 29 May 2026 14:39:06 -0400 Subject: [PATCH 3/4] fix check to change object name --- R/utils.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index 8ae55ab5..9364174d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -109,9 +109,10 @@ SS3_extract_df <- function(dat, label) { report_rows <- which(apply(dat, 1, function(row) any(grepl("report:", row)))) if (!any(grepl("report:", dat[end_row + 2]))) { # ID where the next report row is - next_report_row <- report_rows[which(report_rows > start_row)[1]] + end_row <- report_rows[which(report_rows > start_row)[1]] # Go back to the actual end row of target label - end_row <- ifelse(grep(next_report_row - 1, next_blank_rows), next_report_row - 2, next_report_row - 1) + # Only by one under below condition since in clean_dt we are already doing that + if (grep(end_row - 1, next_blank_rows)) end_row <- end_row - 1 } if (is.na(end_row) || length(end_row) == 0) { From dcc4f308362884b73db9a508109dab117e870068 Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Fri, 29 May 2026 16:10:17 -0400 Subject: [PATCH 4/4] fix issue with grepl check --- R/utils.R | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/R/utils.R b/R/utils.R index 9364174d..1058db87 100644 --- a/R/utils.R +++ b/R/utils.R @@ -81,10 +81,11 @@ get_ncol <- function(file, skip = 0) { SS3_extract_df <- function(dat, label) { # Convert to data.table if not already - if (!inherits(dat, "data.table")) { - dat <- data.table::as.data.table(dat) - } + # if (!inherits(dat, "data.table")) { + # dat <- data.table::as.data.table(dat) + # } + dat <- as.data.frame(dat) # Identify all values to be treated as NA na_values <- c("", "-", "#") @@ -107,12 +108,12 @@ SS3_extract_df <- function(dat, label) { # if not --> then use reference to next report as value # Find all report: rows report_rows <- which(apply(dat, 1, function(row) any(grepl("report:", row)))) - if (!any(grepl("report:", dat[end_row + 2]))) { + if (!is.na(end_row) && !any(grepl("report:", dat[end_row + 2, ]))) { # ID where the next report row is end_row <- report_rows[which(report_rows > start_row)[1]] # Go back to the actual end row of target label # Only by one under below condition since in clean_dt we are already doing that - if (grep(end_row - 1, next_blank_rows)) end_row <- end_row - 1 + if (any(grepl(end_row - 1, next_blank_rows))) end_row <- end_row - 1 } if (is.na(end_row) || length(end_row) == 0) { @@ -120,7 +121,9 @@ SS3_extract_df <- function(dat, label) { } # Extract the subset - clean_dt <- data.table::as.data.table(dat[start_row:(end_row - 1), ]) + # row_range <- start_row:(end_row - 1) + clean_dt <- dat[start_row:(end_row - 1), , drop = FALSE] + clean_dt <- data.table::as.data.table(clean_dt) # Efficiently replace specified values with NA for (j in names(clean_dt)) {