nmfs-fish-tools / SSMSE

Management Strategy Evaluation (MSE) using Stock Synthesis (SS3)
https://nmfs-fish-tools.github.io/SSMSE
MIT License
18 stars 11 forks source link

warnings from `write.table()` b/c append = TRUE when no file exists #192

Closed kellijohnson-NOAA closed 7 months ago

kellijohnson-NOAA commented 7 months ago

The following code leads to several warning messages when running the tests because you are "appending" to an empty file in the "else" part of the statement https://github.com/nmfs-fish-tools/SSMSE/blob/0c3dc2894c62a85f3465cba2cd69f495490c5877/R/extendOM.R#L499-L521 Here is an example of one of the warning messages you see in the formal tests

── Warning ('test-interim.R:31:3'): run_SSMSE runs with interim assessment workflow ──
appending column names to file
Backtrace:
    ▆
 1. └─SSMSE::run_SSMSE(...) at test-interim.R:31:3
 2.   └─SSMSE:::run_SSMSE_scen(...) at SSMSE/R/runSSMSE.R:187:5
 3.     ├─base::tryCatch(...) at SSMSE/R/runSSMSE.R:376:7
 4.     │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 5.     │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 6.     │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
 7.     └─SSMSE:::run_SSMSE_iter(...) at SSMSE/R/runSSMSE.R:376:7
 8.       └─SSMSE:::update_OM(...) at SSMSE/R/runSSMSE.R:679:5
 9.         └─utils::write.table(...) at SSMSE/R/extendOM.R:511:9

I recommend the following change rather than the if/else statement, and I am happy to put it in a pull request or even the current fix-checks PR if you want.

      utils::write.table(
        x = search_log,
        file = file.path(OM_dir, "OM_catch_search_log.csv"),
        append = file.exists(file.path(OM_dir, "OM_catch_search_log.csv")),
        row.names = FALSE,
        col.names = !file.exists(file.path(OM_dir, "OM_catch_search_log.csv")),
        sep = ",",
        dec = ".",
        qmethod = "double"
      )
k-doering-NOAA commented 7 months ago

Thanks @kellijohnson-NOAA ! I'm adding this to my SSMSE "to do list" for tomorrow.