From 149cfedac64709276be056cbaa182dded39ea951 Mon Sep 17 00:00:00 2001 From: e-gugliotti-NOAA Date: Mon, 20 May 2024 17:02:54 -0400 Subject: [PATCH] some changes --- R/MS_functions.R | 7 +++++- R/develtools.R | 2 +- R/initOM.R | 21 ++++++++++++---- R/results.R | 11 +++++++-- R/runSS.R | 32 +++++++++++++++---------- inst/bin/Linux64/{ss => ss3} | Bin inst/bin/MacOS/{ss => ss3} | Bin inst/bin/Windows64/{ss.exe => ss3.exe} | Bin 8 files changed, 52 insertions(+), 21 deletions(-) rename inst/bin/Linux64/{ss => ss3} (100%) mode change 100755 => 100644 rename inst/bin/MacOS/{ss => ss3} (100%) mode change 100755 => 100644 rename inst/bin/Windows64/{ss.exe => ss3.exe} (100%) diff --git a/R/MS_functions.R b/R/MS_functions.R index 29f99db8..79799981 100644 --- a/R/MS_functions.R +++ b/R/MS_functions.R @@ -673,9 +673,14 @@ Interim <- function(EM_out_dir = NULL, EM_init_dir = NULL, run_EM(EM_dir = EM_out_dir, verbose = verbose, check_converged = TRUE) + data_filename <- if(file.exists(file.path(OM_dir, "data.ss_new"))) { + "data.ss_new" + } else { + "data_echo.ss_new" + } Reference_dat <- SS_readdat( - file = file.path(EM_out_dir, "data.ss_new"), + file = file.path(EM_out_dir, data_filename), version = 3.30, section = 2, verbose = FALSE ) diff --git a/R/develtools.R b/R/develtools.R index c3e05bc4..b7ab32cf 100644 --- a/R/develtools.R +++ b/R/develtools.R @@ -28,7 +28,7 @@ test_no_par <- function(orig_mod_dir, new_mod_dir) { try(run_ss_model(new_mod_dir, "-maxfn 0 -phase 50 -nohess", verbose = FALSE)) # read in the 2 par files. orig_par <- readLines(file.path(orig_mod_dir, "ss.par")) - if (file.exists(file.path(new_mod_dir, "data.ss_new"))) { + if (file.exists(file.path(new_mod_dir, "data.ss_new")) || file.exists(file.path(new_mod_dir, "data_echo.ss_new"))) { new_par <- readLines(file.path(new_mod_dir, "ss.par")) if (length(orig_par) != length(new_par)) { new_par_names <- grep("^# [^N]", new_par, value = TRUE) diff --git a/R/initOM.R b/R/initOM.R index 5ec7b050..86031873 100644 --- a/R/initOM.R +++ b/R/initOM.R @@ -384,12 +384,17 @@ create_OM <- function(OM_out_dir, ) } # check model runs without producing nans in the data file - tmp_new_dat <- readLines(file.path(OM_out_dir, "data.ss_new")) + data_filepath <- if(file.exists(file.path(OM_out_dir, "data.ss_new"))) { + file.path(OM_out_dir, "data.ss_new") + } else { + file.path(OM_out_dir, "data_echo.ss_new") + } + tmp_new_dat <- readLines(data_filepath) nan_vals <- grep("nan", tmp_new_dat) if (length(nan_vals) > 0) { stop( - "NAN values present in the data.ss_new om file, suggesting an issue ", - "setting up the OM. See ", file.path(OM_out_dir, "data.ss_new") + "NAN values present in the ", basename(data_filepath)," om file, suggesting an issue ", + "setting up the OM. See ", data_filepath ) } @@ -487,14 +492,20 @@ run_OM <- function(OM_dir, debug_par_run = debug_par_run ) - dat <- r4ss::SS_readdat(file.path(OM_dir, "data.ss_new"), + data_filename <- if(file.exists(file.path(OM_dir, "data.ss_new"))) { + "data.ss_new" + } else { + "data_echo.ss_new" + } + + dat <- r4ss::SS_readdat(file.path(OM_dir, data_filename), section = max_section, verbose = FALSE ) # replace with the expected catch values if sample_catch is FALSE and using # bootstrap if (boot == TRUE & sample_catch == FALSE) { - exp_vals <- r4ss::SS_readdat(file.path(OM_dir, "data.ss_new"), + exp_vals <- r4ss::SS_readdat(file.path(OM_dir, data_filename), section = 2, verbose = FALSE ) diff --git a/R/results.R b/R/results.R index ff1ac37a..e106e642 100644 --- a/R/results.R +++ b/R/results.R @@ -139,10 +139,17 @@ plot_index_sampling <- function(dir = getwd()) { full.names = FALSE ), value = TRUE) assertive.types::assert_is_a_string(om_name) + + data_file <- if(file.exists(file.path(dir, as.character(iters[1]), om_name, "data.ss_new"))){ + "data.ss_new" + } else { + "data_echo.ss_new" + } + tmp_dat_OM <- r4ss::SS_readdat( file.path( dir, as.character(iters[1]), - om_name, "data.ss_new" + om_name, data_file ), verbose = FALSE, section = 1 ) @@ -154,7 +161,7 @@ plot_index_sampling <- function(dir = getwd()) { tmp_dat_OM <- r4ss::SS_readdat( file.path( dir, as.character(iters[1]), - om_name, "data.ss_new" + om_name, data_file ), verbose = FALSE, section = 2 ) diff --git a/R/runSS.R b/R/runSS.R index 8cab179a..eb6ff769 100644 --- a/R/runSS.R +++ b/R/runSS.R @@ -3,17 +3,17 @@ #' Run an operating or estimation model #' -#' This function takes care of calling SS. Importantly, it parses whether the +#' This function takes care of calling SS3. Importantly, it parses whether the #' user is on Unix or Windows and calls the binary correctly. This lower-level #' function is meant to be called by higher level functions. Modified from #' run_ss3model in \href{https://github.com/ss3sim/ss3sim}{ss3sim}. #' #' #' @param dir The full or relative path to the model directory -#' @param admb_options Any options to pass to SS command. Should be +#' @param admb_options Any options to pass to SS3 command. Should be #' of the form '-option'. Note that no checks are done to ensure this is a #' valid ADMB command -#' @param ss_bin Name of the SS executable. Defaults to "ss" +#' @param ss3_bin Name of the SS3 executable. Defaults to "ss3" #' @param ignore.stdout Passed to \code{system}. If \code{TRUE} then ADMB #' output is not printed on screen. This will be slightly faster. Set to #' \code{FALSE} to help with debugging. @@ -39,7 +39,7 @@ #' @author Sean C. Anderson, Kathryn Doering run_ss_model <- function(dir, admb_options = "", - ss_bin = "ss", + ss3_bin = "ss3", ignore.stdout = TRUE, admb_pause = 0.05, show.output.on.console = FALSE, @@ -53,15 +53,23 @@ run_ss_model <- function(dir, wd_orig <- getwd() on.exit(setwd(wd_orig)) os <- .Platform[["OS.type"]] - bin <- get_bin(ss_bin) + bin <- get_bin(ss3_bin) if (check_run == TRUE) { - ss_new_path <- file.path(dir, "data.ss_new") + # new data file named for ss3 v.3.30.18 and prior + if(file.exists(file.path(dir, "data.ss_new"))) { + ss_new_path <- file.path(dir, "data.ss_new") + } + # new data file named for ss3 v.3.30.19 and after + if(file.exists(file.path(dir, "data_echo.ss_new"))) { + ss_new_path <- file.path(dir, "data_echo.ss_new") + } + if (file.exists(ss_new_path)) { file.remove(ss_new_path) } } - if (verbose) message("Running SS.") + if (verbose) message("Running SS3.") if (os == "unix") { system( paste0( @@ -88,7 +96,7 @@ run_ss_model <- function(dir, } else { stop( "data.ss_new was not created during the model run, which suggests ", - "SS did not run correctly" + "SS3 did not run correctly" ) } } else { @@ -104,8 +112,8 @@ run_ss_model <- function(dir, #' Get the binary/executable location in the package SSMSE. This function #' is from \href{https://github.com/ss3sim/ss3sim}{ss3sim}. #' -#' @param bin_name Name of SS3 binary, defaults to "ss" -#' @return The path to an SS binary. If using the GitHub version of the +#' @param bin_name Name of SS3 binary, defaults to "ss3" +#' @return The path to an SS3 binary. If using the GitHub version of the #' package, this will be an internal binary. Otherwise, this function #' will search for a version of the binary in your path. See the #' ss3sim vignette. @@ -114,7 +122,7 @@ run_ss_model <- function(dir, #' \dontrun{ #' get_bin() #' } -get_bin <- function(bin_name = "ss") { +get_bin <- function(bin_name = "ss3") { # code inspiration from glmmADMB package: if (.Platform[["OS.type"]] == "windows") { platform <- "Windows64" @@ -161,7 +169,7 @@ get_bin <- function(bin_name = "ss") { bin <- Sys.which(bin_name)[[1]] if (bin == "") { stop( - "The expected SS executable, ", bin_name, ", was not found in your", + "The expected SS3 executable, ", bin_name, ", was not found in your", " path. See the ss3sim vignette and ?ss3sim::run_ss3model for ", "instructions." ) diff --git a/inst/bin/Linux64/ss b/inst/bin/Linux64/ss3 old mode 100755 new mode 100644 similarity index 100% rename from inst/bin/Linux64/ss rename to inst/bin/Linux64/ss3 diff --git a/inst/bin/MacOS/ss b/inst/bin/MacOS/ss3 old mode 100755 new mode 100644 similarity index 100% rename from inst/bin/MacOS/ss rename to inst/bin/MacOS/ss3 diff --git a/inst/bin/Windows64/ss.exe b/inst/bin/Windows64/ss3.exe similarity index 100% rename from inst/bin/Windows64/ss.exe rename to inst/bin/Windows64/ss3.exe