From 22a5583be733e1862e5210bf42f78066defc4c1d Mon Sep 17 00:00:00 2001 From: stevencarlislewalker Date: Fri, 15 Nov 2024 14:22:17 -0500 Subject: [PATCH] log files organized by session --- DESCRIPTION | 2 +- R/log_files.R | 10 +++++++++- R/zzz.R | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae7114db..33a7b6b5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: macpan2 Title: Fast and Flexible Compartmental Modelling -Version: 1.11.0 +Version: 1.11.1 Authors@R: c( person("Steve Walker", email="swalk@mcmaster.ca", role=c("cre", "aut")), person("Weiguang Guan", role="aut"), diff --git a/R/log_files.R b/R/log_files.R index 5741742b..900b4dc8 100644 --- a/R/log_files.R +++ b/R/log_files.R @@ -14,7 +14,8 @@ #' * Other methods inherited from \code{\link{Files}} #' #' @noRd -LogFile = function(directory = tempdir()) { +LogFile = function(directory = NULL) { + if (is.null(directory)) directory = mp_session_dir() self = Files(fix_dir(directory), reader_spec("log.txt", TXTReader)) self$log = function() self$get("log") self$data_arg = function() list(log_file = self$.file_path("log")) @@ -27,6 +28,13 @@ LogFile = function(directory = tempdir()) { return_object(self, "LogFile") } +mp_session_dir = function() { + session_name = getOption("macpan2_session_name") + wd = getwd() + ld = file.path(wd, ".macpan", session_name) + if (!dir.exists(ld)) dir.create(ld, recursive = TRUE) + return(ld) +} make_file = function(directory) { file_path = file.path(directory, "log.txt") file.create(file_path) diff --git a/R/zzz.R b/R/zzz.R index f6619969..ff06461a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -9,6 +9,8 @@ , macpan2_vec_by = c("state", "flow_rates", "trans_rates") |> self_named_vector() #, macpan2_memoise = TRUE + # where the log files go (e.g. `.macpan2/default`) + , macpan2_session_name = "default" # tolerances , macpan2_tol_hazard_div = 1e-8