objects
slot of a simList
objectR/check.R
checkObject.Rd
Check that a named object exists in the provide simList
environment slot,
and optionally has desired attributes.
checkObject(sim, name, object, layer, ...)
# S4 method for class 'simList,ANY,ANY'
checkObject(sim, name, object, layer, ...)
# S4 method for class 'simList,character,missing'
checkObject(sim, name, object, layer, ...)
# S4 method for class 'missing,ANY,ANY'
checkObject(sim, name, object, layer, ...)
A simList()
object.
A character string specifying the name of an object to be checked.
An object. This is mostly used internally, or with layer, because it will fail if the object does not exist.
Character string, specifying a layer name in a Raster, if the
name
is a Raster*
object.
Additional arguments. Not implemented.
Invisibly return TRUE
indicating object exists; FALSE
if not.
sim <- simInit()
#> Setting:
#> options(
#> reproducible.cachePath = '/tmp/Rtmp45trFG/reproducible/cache'
#> spades.inputPath = '/tmp/Rtmp45trFG/SpaDES/inputs'
#> spades.outputPath = '/tmp/Rtmp45trFG/SpaDES/outputs'
#> spades.modulePath = '/tmp/Rtmp45trFG/SpaDES/modules'
#> spades.scratchPath = '/tmp/Rtmp45trFG/SpaDES/scratch'
#> )
#> Nov21 04:22:21 simInit Using setDTthreads(1). To change: 'options(spades.DTthreads = X)'.
#> Elpsed time for simInit: 0.02528381 secs
sim$a <- 1
sim$b <- list(d = 1)
sim$r <- terra::rast(terra::ext(0,2,0,2), res = 1, vals = 2)
sim$s <- c(sim$r, terra::rast(terra::ext(0,2,0,2), res = 1, vals = 3))
names(sim$s) <- c("r1", "r2") # give layer names
(checkObject(sim, name = "a")) # TRUE
#> [1] TRUE
(checkObject(sim, name = "b", layer = "d")) # TRUE
#> [1] TRUE
(checkObject(sim, name = "d")) # FALSE
#> object does not exist.
#> [1] FALSE
(checkObject(sim, name = "r")) # TRUE
#> [1] TRUE
(checkObject(sim, object = sim$s)) # TRUE
#> [1] TRUE
(checkObject(sim, object = sim$s, layer = "r1")) # TRUE
#> [1] TRUE