Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpaDES.core::P bugfix; Elapsed time spelling; Elapsed Time units improvement #286

Merged
merged 6 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading