Skip to content

Commit

Permalink
Merge pull request #286 from PredictiveEcology/Pbug
Browse files Browse the repository at this point in the history
SpaDES.core::P bugfix; Elapsed time spelling; Elapsed Time units improvement
  • Loading branch information
eliotmcintire committed Jun 7, 2024
2 parents 45bc4a9 + 16d57dc commit 58a3d19
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Description: Provides the core framework for a discrete event system to
URL:
https://spades-core.predictiveecology.org/,
https://github.com/PredictiveEcology/SpaDES.core
Date: 2024-06-06
Version: 2.1.3
Date: 2024-06-07
Version: 2.1.4
Authors@R: c(
person("Alex M", "Chubaty", , "achubaty@for-cast.ca", role = c("aut"),
comment = c(ORCID = "0000-0001-7146-8135")),
Expand Down
3 changes: 2 additions & 1 deletion R/restart.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ restartSpades <- function(sim = NULL, module = NULL, numEvents = Inf, restart =
fd1 <- fd1[!unlist(unname(fd1)) %in% unlist(unname(fd2))]
}
# move the changed ones to the simList
list2env(objsToCopy[names(fd1)], envir = sim@.xData)
if (NROW(fd1))
list2env(objsToCopy[names(fd1)], envir = sim@.xData)
}

modObjNames <- names(sim$.recoverableModObjs[[event]])
Expand Down
20 changes: 9 additions & 11 deletions R/simList-accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ P.simList <- function(sim, param, module) {
modFilePaths <- checkPath(names(mods))

scalls <- sys.calls()
whereInSC <- .grepSysCalls(scalls, "^P\\(")
whereInSC <- .grepSysCalls(scalls, "^P\\(|^SpaDES.core::P\\(")
while (whereInSC > 1) {
poss <- scalls[whereInSC - 1]
fn <- as.character(poss[[1]][[1]])
Expand Down Expand Up @@ -3351,22 +3351,20 @@ elapsedTime.simList <- function(x, byEvent = TRUE, units = "auto", ...) {
if (identical(units, "auto")) {
unt <- "secs"
if (any(a > minutesInSeconds)) {
if (any(a > hoursInSeconds)) {
if (any(a > daysInSeconds)) {
unt <- "days"
}
} else {
unt <- "hours"
}
} else {
unt <- "mins"
} else if (any(a > hoursInSeconds)) {
unt <- "hours"
} else if (any(a > daysInSeconds)) {
unt <- "days"
}
st <- Sys.time()
a <- round(difftime(a + st, st, units = unt), 3) # work around for forcing a non seconds unit, allowing "auto"
} else {
# This one won't allow "auto"
unt <- units
units(a) <- units
}
st <- Sys.time()
a <- round(difftime(a + st, st, units = unt), 3) # work around for forcing a non seconds unit, allowing "auto"

ret[, elapsedTime := a]
} else {
ret <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/simulation-simInit.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ setMethod(
sim <- elapsedTimeInSimInit(._startClockTime, sim)
._startClockTime <- Sys.time()
dt <- difftime(._startClockTime, ._startClockTime - sim$._simInitElapsedTime)
message("Elpsed time for simInit: ", format(dt, format = "auto"))
message("Elapsed time for simInit: ", format(dt, format = "auto"))
}, add = TRUE)

paths <- lapply(paths, function(p) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ test_that("test .robustDigest for simLists", {
"Setting", "Paths", "using dataPath", "Using setDTthreads",
"with user supplied tags",
"There is no similar item in the cachePath",
"Saving", "Done", "Elpsed time for", sep = "|")
"Saving", "Done", "Elapsed time for", sep = "|")
expect_true(all(grepl(msgGrep11, mess1)))

msgGrep <- "Running .input|loaded cached copy|module code|Setting|Paths"
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-mod.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ test_that("local mod object", {

## Need "Copy" in this sequence because the event queue is actually an environment :)
## so the LHS will have the updated event queue, but the parameters will be at initial conditions

# quick test for SpaDES.core::P utilization
expect_true(SpaDES.core::P(mySim3, "testParB", "test2") == 1197)

expect_true(P(mySim3)$test2$testParB == 1197) # .globals + .inputObjects
mySim4 <- spades(Copy(mySim3), events = "init")
expect_true(P(mySim4)$test2$testParB == 1953) ## .globals + .inputObjects + init
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ test_that("conflicting function types", {
"Running .inputObjects|",
"Setting:|Paths set to:|",
"Using setDTthreads|",
m, ": using dataPath|", "Elpsed")))))
m, ": using dataPath|", "Elapsed")))))

# assign to sim for functions like scheduleEvent
lineWithScheduleEvent <- grep(xxx, pattern = "scheduleEvent")[1]
Expand Down Expand Up @@ -936,6 +936,7 @@ test_that("simInitAndSpades", {
spades(debug = FALSE)

expect_true(all.equal(mySim, mySim2))

})

test_that("scheduleEvent with invalid values for eventTime", {
Expand Down

0 comments on commit 58a3d19

Please sign in to comment.