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

Use box for package isolation in modules #293

Open
wants to merge 67 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
ca0a296
createDESCRIPTIONandDocs
Jun 19, 2024
b0dfdb1
bugfix when debug = 2 ... spades call errors with Error in class(xx) …
Jun 22, 2024
96c5eab
fixes for test-mod
Jun 25, 2024
b91a295
use box::use
Jun 27, 2024
81a5e30
mod masking from other packages e.g., magrittr
Jul 5, 2024
2628562
add box to DESCRIPTION
Jul 5, 2024
83c5f4f
Merge branch 'development' into box
Oct 28, 2024
67be609
minor
Nov 4, 2024
a800f29
cleaning
Nov 5, 2024
a77e724
restartSpades doesn't have clockTime
Nov 5, 2024
bb1eadc
test updates
Nov 5, 2024
69d826e
start using gitcreds
Nov 5, 2024
221d19f
quieter tests
Nov 5, 2024
0b7d14e
hide Rstudio bug about "package:stats" may not be available
Nov 13, 2024
e2db4c9
uncomment tests
Nov 13, 2024
b8093c1
new spadesOptions -- spades.reqdPkgsDontLoad - to explicitly prevent …
Nov 13, 2024
83757b4
Merge branch 'reqdPkgsDontLoad' into box
Nov 13, 2024
71d6b2e
options("spades.useBox"); redoc
Nov 13, 2024
858ee7c
reqdPkgsDontLoad
Nov 13, 2024
2c3176b
Merge branch 'reqdPkgsDontLoad' into box
Nov 13, 2024
a9552db
doc fail
Nov 13, 2024
419a442
Merge branch 'reqdPkgsDontLoad' into box
Nov 13, 2024
221da24
Revert "restartSpades doesn't have clockTime"
Nov 26, 2024
8b8c56a
when copying over objs from Cache, don't copy ._*** objs; they are si…
eliotmcintire Nov 26, 2024
47659ab
Merge remote-tracking branch 'origin/development' into box
Nov 26, 2024
71c95ab
restartSpades needs temporary sim@current; like simInit
Dec 2, 2024
b8b37de
bugfix useBox --> getOption(spades.useBox)
Dec 2, 2024
63a5e11
restartSpades with box fix; pkgs
eliotmcintire Dec 2, 2024
bdff6ae
allow parameter class to be a vector
eliotmcintire Dec 16, 2024
a167fa2
missing userTags in spades module calls
eliotmcintire Dec 18, 2024
c114055
Merge branch 'paramsWithClassVector' into box
Dec 18, 2024
bcde50b
Merge branch 'userTags' into box
Dec 18, 2024
cfea4d3
bump version
Dec 18, 2024
732c192
quick = FALSE default for objSize.simList
eliotmcintire Dec 20, 2024
d918a83
restartSpades mods; saveState
eliotmcintire Dec 20, 2024
73d809a
saveSimList add files as explicit param; bugfix inputFNs
eliotmcintire Dec 20, 2024
f4afcc0
protect using box with spades.useBox
eliotmcintire Dec 20, 2024
0d029e1
._startClockTime fixes in simInit; debugToVerbose
eliotmcintire Dec 20, 2024
086ff8b
debugToVerbose in spades
eliotmcintire Dec 20, 2024
bec480f
createDESCRIPTIONandDocs updates for missing .RbuildIgnore; add verbose
eliotmcintire Dec 20, 2024
a6e5c63
muffleWarning for package:stats may not be available
eliotmcintire Dec 20, 2024
549a985
useBox option
eliotmcintire Dec 20, 2024
577f034
clean up recovery mode in simulation-spades.R
eliotmcintire Dec 20, 2024
7176e46
Merge branch 'paramsWithClassVector' into box
Dec 21, 2024
cf87fcc
Plots for SpatRaster tweak
eliotmcintire Jan 10, 2025
6d3bc15
Merge branch 'box' of github.com:PredictiveEcology/SpaDES.core into box
eliotmcintire Jan 10, 2025
1dd6d35
.wrap.simList missing a cacheId
Jan 11, 2025
97ab870
Merge remote-tracking branch 'origin/box' into box
Jan 11, 2025
1072415
suppliedElsewhere: use loadOrder to include known cyclic starting
eliotmcintire Jan 11, 2025
7aa7afc
Merge branch 'box' of github.com:PredictiveEcology/SpaDES.core into box
eliotmcintire Jan 11, 2025
953d6c1
Bump 2.1.5.9007
Jan 11, 2025
5b1fc29
dealing with updated reproducible;
Jan 17, 2025
cab26c1
objSize updates -- use `.objSizeWithTry` b/c bug in lobstr
Jan 17, 2025
34af0b7
rename with "_": ._spadesDebugWidth
Jan 17, 2025
f8b1102
add "package:stats" warning catch
Jan 17, 2025
40cbf87
redoc; bump min reproducible
Jan 17, 2025
e6c38b8
getModuleVersion -- add moduleFiles arg -- no need to check internet 2x
Jan 17, 2025
03de272
rm ::: and redoc
Jan 17, 2025
a417bf2
use objects instead of txt for hidden sim objects
Jan 18, 2025
af7ddda
R CMD check
Jan 18, 2025
f2145e0
Bump
Jan 18, 2025
bee4ed2
._txtClockTime needs
Jan 19, 2025
bdf42da
test elapsedTime.simList
Jan 19, 2025
b21667c
R CMD checking
eliotmcintire Jan 20, 2025
5b3e68d
rm .modifySearchPath
Jan 22, 2025
4840114
Merge remote-tracking branch 'origin/box' into box
Jan 22, 2025
dc963c5
Merge remote-tracking branch 'origin/development' into box
Jan 23, 2025
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
10 changes: 7 additions & 3 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-10-13
Version: 2.1.5.9002
Date: 2025-01-17
Version: 2.1.5.9008
Authors@R: c(
person("Alex M", "Chubaty", , "[email protected]", role = c("aut"),
comment = c(ORCID = "0000-0001-7146-8135")),
Expand All @@ -31,8 +31,9 @@ Authors@R: c(
Depends:
R (>= 4.2),
quickPlot (>= 1.0.2),
reproducible (>= 2.1.1)
reproducible (>= 2.1.2.9006)
Imports:
box,
cli,
data.table (>= 1.11.0),
fs,
Expand All @@ -51,11 +52,13 @@ Suggests:
CircStats,
codetools,
covr,
DBI,
DiagrammeR (>= 0.8.2),
future,
future.callr,
ggplot2,
ggplotify,
gitcreds,
httr,
knitr,
lattice,
Expand Down Expand Up @@ -102,6 +105,7 @@ Collate:
'code-checking.R'
'convertToPackage.R'
'copy.R'
'createDESCRIPTIONandDocs.R'
'debugging.R'
'downloadData.R'
'simulation-parseModule.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export(conditionalEvents)
export(convertTimeunit)
export(convertToPackage)
export(copyModule)
export(createDESCRIPTIONandDocs)
export(createsOutput)
export(current)
export(currentModule)
Expand Down Expand Up @@ -187,6 +188,7 @@ export(restartSpades)
export(rndstr)
export(saveFiles)
export(saveSimList)
export(saveState)
export(savedSimEnv)
export(scheduleConditionalEvent)
export(scheduleEvent)
Expand Down Expand Up @@ -397,6 +399,7 @@ importFrom(reproducible,.cacheMessageObjectToRetrieve)
importFrom(reproducible,.checkCacheRepo)
importFrom(reproducible,.file.move)
importFrom(reproducible,.grepSysCalls)
importFrom(reproducible,.objSizeWithTry)
importFrom(reproducible,.orderDotsUnderscoreFirst)
importFrom(reproducible,.preDigestByClass)
importFrom(reproducible,.prepareOutput)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

* fix issue with `Plots()` where plots were discarded if no filename was specified;
* minor documentation improvements;
* new option: `spades.reqdPkgsDontLoad`, a character vector. If anything is specified,
then it will not be loaded with `require` or `library`, but it will be installed, if needed,
and if `spades.useRequire = TRUE`, which is the default. Default for this new option is
"box", which is one of potentially many in the R universe that throws an error if it is
loaded.

# SpaDES.core 2.1.5

Expand Down
4 changes: 2 additions & 2 deletions R/Plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ ggplotClassesCanHandle <- c("eps", "ps", "tex", "pdf", "jpeg", "tiff", "png", "b
#' .plotInitialTime = 1)
#' }
#' } # end ggplot
#' unlink("figures") # clean up
#' } # end of dontrun
Plots <- function(data, fn, filename,
types = quote(params(sim)[[currentModule(sim)]]$.plots),
Expand Down Expand Up @@ -333,7 +334,7 @@ Plots <- function(data, fn, filename,
}

if (needSaveRaw) {
if (is(data, "Raster")) {
if (is(data, "Raster") || is(data, "SpatRaster")) {
rasterFilename <- file.path(path, paste0(filename, "_data.tif"))
writeRaster(data, filename = rasterFilename, overwrite = TRUE)
if (exists("sim", inherits = FALSE))
Expand All @@ -355,7 +356,6 @@ Plots <- function(data, fn, filename,
)
}
}

if (needSave) {
if (is.null(simIsIn)) {
if (is.call(path))
Expand Down
38 changes: 25 additions & 13 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ setMethod(
definition = function(object, preDigest, origArguments, ...) {
dots <- list(...)
whSimList <- which(unlist(lapply(origArguments, is, "simList")))[1]
whSimList <- names(whSimList)

# remove the "newCache" attribute, which is irrelevant for digest
if (!is.null(attr(object, ".Cache")$newCache)) {
Expand Down Expand Up @@ -684,8 +685,10 @@ setMethod(
}
# Now changed objects
if (length(unlist(changedModEnvObjs))) {
# if (identical(currentModule(object), "canClimateData")) browser()
Map(nam = names(changedModEnvObjs), objs = changedModEnvObjs, function(nam, objs) {
objNames <- names(objs$.objects)
objNames <- names(objs$.objects) # used to be "names(...)" -- but don't want `._` objs
objNames <- grep("^._.+", objNames, value = TRUE, invert = TRUE)
if (!is.null(objNames))
list2env(mget(objNames, envir = [email protected]$.mods[[nam]][[".objects"]]),
envir = [email protected]$.mods[[nam]][[".objects"]])
Expand Down Expand Up @@ -914,7 +917,7 @@ if (!exists("objSize")) {
#' and the other slots in the `simList` (e.g., events, completed, modules, etc.).
#' The returned object also has an attribute, "total", which shows the total size.
#'
#' @importFrom reproducible objSize
#' @importFrom reproducible objSize .objSizeWithTry
#' @importFrom lobstr obj_size
#' @inheritParams reproducible::objSize
#'
Expand All @@ -925,18 +928,27 @@ if (!exists("objSize")) {
#' a <- simInit(objects = list(d = 1:10, b = 2:20))
#' objSize(a)
#' utils::object.size(a)
objSize.simList <- function(x, quick = TRUE, ...) {
objSize.simList <- function(x, quick = FALSE, recursive = FALSE, ...) {

total <- obj_size(x, quick = TRUE)
aa <- objSize([email protected], quick = quick, ...)
total <- .objSizeWithTry(x)
# total <- try(obj_size(x, quick = TRUE), silent = TRUE) # failing due to lobstr issue #72
if (!is(total, "try-error") && isTRUE(recursive)) {
aa <- objSize([email protected], quick = quick, recursive = recursive, ...)

simSlots <- grep("^\\.envir$|^\\.xData$", slotNames(x), value = TRUE, invert = TRUE)
names(simSlots) <- simSlots
otherParts <- objSize(lapply(simSlots, function(slotNam) slot(x, slotNam)), quick = quick, ...)
simSlots <- grep("^\\.envir$|^\\.xData$", slotNames(x), value = TRUE, invert = TRUE)
names(simSlots) <- simSlots
otherParts <- objSize(lapply(simSlots, function(slotNam) slot(x, slotNam)), quick = quick, ...)

if (!quick)
attr(total, "objSizes") <- list(sim = attr(aa, "objSize"),
other = attr(otherParts, "objSize"))
# if (!quick)
attr(total, "objSize") <- list(sim = attr(aa, "objSize"),
other = attr(otherParts, "objSize"))
# browser()
# attr(total, "objSize") <- sum(unlist(attr(aa, "objSize")), unlist(attr(otherParts, "objSize")))
# class(attr(total, "objSize")) <- "lobstr_bytes"

} # else {
# total <- NA
# }

return(total)
}
Expand All @@ -961,7 +973,7 @@ objSize.simList <- function(x, quick = TRUE, ...) {
.wrap.simList <- function(obj, cachePath, preDigest, drv = getOption("reproducible.drv", NULL),
conn = getOption("reproducible.conn", NULL),
verbose = getOption("reproducible.verbose"),
outputObjects = NULL,
outputObjects = NULL, cacheId,
...) {

# Copy everything (including . and ._) that is NOT a main object -- objects are the potentially very large things
Expand All @@ -987,7 +999,7 @@ objSize.simList <- function(x, quick = TRUE, ...) {
# Deal with the potentially large things -- convert to list -- not a copy
obj2 <- as.list(obj, all.names = FALSE) # don't copy the . or ._ objects, already done
# Now the individual objects
out <- .wrap(obj2, cachePath = cachePath, outputObjects = outputObjects,
out <- .wrap(obj2, cachePath = cachePath, outputObjects = outputObjects, cacheId = cacheId,
drv = drv, conn = conn, verbose = verbose, ...)

# for (objName in names(out)) obj[[objName]] <- NULL
Expand Down
Loading
Loading