Functions for the
simtimes slot of a
and its elements. To maintain modularity, the behaviour of these functions depends
on where they are used. In other words, different modules can have their own
SpaDES converts these to seconds when running a simulation, but
shows the user time in the units of the model as shown with
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
times(x, ...) ## S4 method for signature 'simList' times(x) times(x) <- value ## S4 replacement method for signature 'simList' times(x) <- value ## S3 method for class 'simList' time(x, unit, ...) time(x) <- value ## S4 replacement method for signature 'simList' time(x) <- value end(x, ...) ## S3 method for class 'simList' end(x, unit, ...) end(x) <- value ## S4 replacement method for signature 'simList' end(x) <- value start(x, ...) ## S3 method for class 'simList' start(x, unit = NULL, ...) start(x) <- value ## S4 replacement method for signature 'simList' start(x) <- value timeunit(x) ## S4 method for signature 'simList' timeunit(x) timeunit(x) <- value ## S4 replacement method for signature 'simList' timeunit(x) <- value timeunits(x) ## S4 method for signature 'simList' timeunits(x) elapsedTime(x, ...) ## S3 method for class 'simList' elapsedTime(x, byEvent = TRUE, ...)
A time, given as a numeric, optionally with a unit attribute, but this will be deduced from the model time units or module time units (if used within a module).
Character. One of the time units used in
timeunit will extract the current units of the time used in a
simulation (i.e., within a
If it is set within a
times=list(start=0, end=52, timeunit = "week"), it will set the
units for that simulation.
By default, a
simInit call will use the smallest unit contained within
the metadata for the modules being used. If there are parent modules, then the
parent module timeunit will be used even if one of its children is a smaller timeunit.
If all modules, including parents, are set to
timeunit defaults to seconds.
If parents are set to
NA, then the set of modules defined by that parent module
will be given the smallest units of the children.
Currently, available units are "second", "hours", day", "week", "month", and "year" can be used in the metadata of a module.
The user can also define a new unit. The unit name can be anything, but the
function definition must be of the form
The unit name is the part without the
d and the function name definition
d. This new function, e.g.,
dfortnight <- function(x) lubridate::duration(dday(14))
can be placed anywhere in the search path or in a module.
timeunits will extract the current units of the time of all
modules used in a simulation.
This is different from
timeunit because it is not necessarily
associated with a
In many cases, the "simpler" use of each of these functions may be slower
computationally. For instance, it is much faster to use
time(sim). So as a module developer, it is advantageous to
write out the longer one, minimizing the looking up that R must do.
Returns or sets the value of the slot from the
These have default behaviour that is based on the calling frame timeunit. When used inside a module, then the time is in the units of the module. If used in an interactive mode, then the time will be in the units of the simulation.
Additional methods are provided to access the current, start, and end times of the simulation:
||Current simulation time.|
||Simulation start time.|
||Simulation end time.|
||List of all simulation times (current, start, end, timeunit).|
Alex Chubaty and Eliot McIntire
SpaDES.core-package, specifically the section 1.2.5 on Simulation times.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.