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) diff --git a/R/utils.R b/R/utils.R index 6ba1da95..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("", "-", "#") @@ -102,12 +103,27 @@ 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 (!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 (any(grepl(end_row - 1, next_blank_rows))) end_row <- end_row - 1 + } + if (is.na(end_row) || length(end_row) == 0) { end_row <- nrow(dat) } # 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)) {