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 simList,ANY,ANY
checkObject(sim, name, object, layer, ...)

# S4 method for simList,character,missing
checkObject(sim, name, object, layer, ...)

# S4 method for missing,ANY,ANY
checkObject(sim, name, object, layer, ...)

Arguments

sim

A simList() object.

name

A character string specifying the name of an object to be checked.

object

An object. This is mostly used internally, or with layer, because it will fail if the object does not exist.

layer

Character string, specifying a layer name in a Raster, if the name is a Raster* object.

...

Additional arguments. Not implemented.

Value

Invisibly return TRUE indicating object exists; FALSE if not.

See also

Author

Alex Chubaty and Eliot McIntire

Examples

sim <- simInit()
#> Setting:
#>   options(
#>     reproducible.cachePath = '/tmp/RtmpNobduY/reproducible/cache'
#>     spades.inputPath = '/tmp/RtmpNobduY/SpaDES/inputs'
#>     spades.outputPath = '/tmp/RtmpNobduY/SpaDES/outputs'
#>     spades.modulePath = '/tmp/RtmpNobduY/SpaDES/modules'
#>     spades.scratchPath = '/tmp/RtmpNobduY/SpaDES/scratch'
#>   )
#> Apr16 20:30:30 simInit Using setDTthreads(1). To change: 'options(spades.DTthreads = X)'.
#> Elpsed time for simInit: 0.02264714 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