Skip to content

Commit

Permalink
refactor: changes suggested by IGT review
Browse files Browse the repository at this point in the history
  • Loading branch information
Chantel Wetzel committed Aug 29, 2022
1 parent ecb0a06 commit f16e1a7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 39 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nwfscDiag
Type: Package
Title: Generate standard NWFSC assessment diagnostics
Version: 2.0
Version: 1.1.0
Author: Chantel Wetzel
Maintainer: Chantel Wetzel <[email protected]>
Description: Package that can automates diagnositics for SS3 models by running jitters, retrospective, and profiles.
Expand Down
4 changes: 1 addition & 3 deletions R/get_settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ get_settings <- function(settings = NULL, verbose = FALSE) {
profile_details = NULL,
version = "3.30",
exe = "ss",
verbose = FALSE,

# Jitter Settings
extras = "-nohess",
Njitter = 100,
show_in_console = TRUE,
printlikes = FALSE,
verbose = FALSE,
jitter_fraction = 0.05,
jitter_init_values_src = NULL,

Expand All @@ -59,8 +59,6 @@ get_settings <- function(settings = NULL, verbose = FALSE) {
whichruns = NULL,
prior_check = FALSE,
read_like = TRUE,
exe = "ss",
verbose = TRUE,
init_values_src = 0
)

Expand Down
26 changes: 5 additions & 21 deletions R/profile_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ profile_wrapper <- function(mydir, model_settings){
# plyr and dplyr.
round_any <- function(x, accuracy, f = round){
f(x / accuracy) * accuracy}

OS <- "Mac" # don't know the version$os info for Mac
if(length(grep("linux", version$os)) > 0) OS <- "Linux"
if(length(grep("mingw", version$os)) > 0) OS <- "Windows"

# figure out name of executable based on 'exe' input which may contain .exe
if(length(grep(".exe", tolower(file.path(mydir, model_settings$base_name)))) == 1) {
Expand All @@ -39,12 +35,8 @@ profile_wrapper <- function(mydir, model_settings){
exe <- paste(model_settings$exe, ifelse(OS == "Windows", ".exe", ""), sep="")
}
# check whether exe is in directory
if(OS == "Windows") {
if(!exe %in% list.files(file.path(mydir, model_settings$base_name)))
stop("Executable ", exe, " not found in ", file.path(mydir, model_settings$base_name))
} else {
if(!exe %in% list.files(file.path(mydir, model_settings$base_name)))
stop("Executable ", exe, " not found in ", file.path(mydir, model_settings$base_name))
if(!exe %in% list.files(file.path(mydir, model_settings$base_name))) {
stop("Executable ", exe, " not found in ", file.path(mydir, model_settings$base_name))
}

N <- nrow(model_settings$profile_details)
Expand Down Expand Up @@ -73,17 +65,9 @@ profile_wrapper <- function(mydir, model_settings){
if (!file.exists(file.path(profile_dir, "control.ss_new"))) {
orig_dir <- getwd()
setwd(profile_dir)
command <- paste(model_settings$model, model_settings$extras)
if(OS != "windows") {
command <- paste( "./", command, sep="")
}
cat("Running model in directory:", getwd(), "\n")
cat("Using the command: '", command, "'\n", sep="")
if(OS == "windows" & !model_settings$systemcmd){
shell(cmd = command)
} else {
system(command)
}
r4ss::run(dir = profile_dir,
exe = model_settings$exe,
extras = model_settings$extras)
setwd(orig_dir)
}

Expand Down
1 change: 0 additions & 1 deletion R/retro_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ retro_wrapper <- function(mydir, model_settings) {
dir = retro_dir,
oldsubdir = model_settings$oldsubdir,
newsubdir = model_settings$newsubdir,
subdirstart = "retro",
years = model_settings$retro_yrs,
overwrite = model_settings$overwrite,
exe = model_settings$exe,
Expand Down
16 changes: 3 additions & 13 deletions R/run_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,14 @@ run_diagnostics <- function(mydir, model_settings ){

# Check for Report file
model_dir <- file.path(mydir, paste0(model_settings$base_name))
OS <- "Mac" # don't know the version$os info for Mac
if(length(grep("linux", version$os)) > 0) OS <- "Linux"
if(length(grep("mingw", version$os)) > 0) OS <- "Windows"

if (!file.exists(file.path(model_dir, "Report.sso"))) {
orig_dir <- getwd()
setwd(model_dir)
command <- paste(model_settings$exe, model_settings$extras)
if(OS != "windows") {
command <- paste( "./", command, sep="")
}
cat("Running model in directory:", getwd(), "\n")
cat("Using the command: '", command, "'\n", sep="")
if(OS == "windows" & !model_settings$systemcmd){
shell(cmd = command)
} else {
system(command)
}
run(dir = model_dir,
exe = model_settings$exe,
extras = model_settings$extras)
setwd(orig_dir)
}

Expand Down

0 comments on commit f16e1a7

Please sign in to comment.