Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions R/convert_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)

Expand All @@ -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)
Expand Down
24 changes: 20 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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("", "-", "#")

Expand All @@ -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)) {
Expand Down
Loading