diff --git a/R/convert_output.R b/R/convert_output.R index 50ffc7af..8b36a2e5 100644 --- a/R/convert_output.R +++ b/R/convert_output.R @@ -475,12 +475,7 @@ convert_output <- function( if ("sexes" %in% colnames(df3)) { df3 <- df3 |> # add in case if sexes is present and add sex as na if so - dplyr::mutate( - sex = dplyr::case_when( - any(grepl("^sexes$", colnames(df3))) ~ sexes, - TRUE ~ NA - ) - ) |> + dplyr::mutate(sex = if (any(grepl("^sexes$", colnames(df3)))) sexes else NA) |> dplyr::select(-sexes) } else { df3 <- dplyr::mutate(df3, sex = NA) @@ -667,7 +662,7 @@ convert_output <- function( label == "f" ~ "fishing_mortality", TRUE ~ label ), - estimate = as.numeric(estimate) + estimate = suppressWarnings(as.numeric(estimate)) # dplyr::if_else( # grepl("-|_", as.numeric(estimate)), # NA, @@ -1425,10 +1420,7 @@ convert_output <- function( out_new <- Reduce(rbind, out_list) out_new <- out_new |> dplyr::mutate( - fleet = dplyr::case_when( - any(unique(out_new$fleet) %in% fleet_names) ~ fleet, - TRUE ~ fleet_names[fleet] - ), + fleet = if (any(unique(out_new$fleet) %in% fleet_names)) fleet else fleet_names[fleet], era = dplyr::case_when( !is.na(era) ~ era, year < start_year ~ "init", @@ -2395,7 +2387,14 @@ convert_output <- function( var_names_sheet <- var_names_sheet |> dplyr::select(-module_name) out_new <- dplyr::left_join(out_new, var_names_sheet, by = "label") } else { - out_new <- dplyr::left_join(out_new, var_names_sheet, by = c("module_name", "label")) + var_names_sheet <- var_names_sheet |> + dplyr::distinct(module_name, label, .keep_all = TRUE) + out_new <- dplyr::left_join( + out_new, + var_names_sheet, + by = c("module_name", "label"), + relationship = "many-to-one" + ) } out_new <- out_new |> dplyr::mutate(label = dplyr::case_when( diff --git a/R/utils_plot.R b/R/utils_plot.R index 3ee0f015..6bd9fa36 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -375,10 +375,7 @@ plot_aa <- function( dplyr::mutate( age = as.numeric(age), # zvar = .data[[z]], - zvar = dplyr::case_when( - proportional ~ sqrt(.data[[z]]), - TRUE ~ .data[[z]] - ) + zvar = if (proportional) sqrt(.data[[z]]) else .data[[z]] ) # Caclaulate x-axis breaks x_n_breaks <- axis_breaks(dat[[x]]) diff --git a/tests/testthat/test-convert_output.R b/tests/testthat/test-convert_output.R index 80f78616..fb0b0119 100644 --- a/tests/testthat/test-convert_output.R +++ b/tests/testthat/test-convert_output.R @@ -25,6 +25,12 @@ test_that("convert_output works for SS3", { expect_equal(dim(output)[2], 34) }) +test_that("convert_output does not emit scalar case_when deprecation warning", { + expect_no_warning(convert_output( + file = fs::path("fixtures", "ss3_models", "models", "Hake_2018", "Report.sso") + )) +}) + test_that("convert_output saves model ss3 hake output file", { dir.create(fs::path("fixtures", "ss3_models_converted", "Hake_2018"), recursive = TRUE) diff --git a/tests/testthat/test-utils_plot.R b/tests/testthat/test-utils_plot.R index 781c475b..dfe4e857 100644 --- a/tests/testthat/test-utils_plot.R +++ b/tests/testthat/test-utils_plot.R @@ -78,7 +78,7 @@ test_that("plot_aa and helper line builders return expected outputs", { group_var = "1" ) - proportional_plot <- plot_aa(aa_dat, proportional = TRUE) + expect_no_warning(proportional_plot <- plot_aa(aa_dat, proportional = TRUE)) expect_s3_class(proportional_plot, "gg") expect_equal(proportional_plot$theme$legend.position, "none")