Convert time units

Description

In addition to using the lubridate package, some additional functions to work with times are provided.

This function takes a numeric with a "unit" attribute and converts it to another numeric with a different time attribute. If the units passed to argument units are the same as attr(time, "unit"), then it simply returns input time.

Usage

 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
inSeconds(unit, envir)

## S4 method for signature 'character,environment'
inSeconds(unit, envir)

## S4 method for signature ''NULL',missing'
inSeconds(unit)

## S4 method for signature 'character,missing'
inSeconds(unit)

convertTimeunit(time, unit, envir)

## S4 method for signature 'numeric,character,environment'
convertTimeunit(time, unit, envir)

## S4 method for signature 'numeric,missing,missing'
convertTimeunit(time)

## S4 method for signature 'numeric,character,missing'
convertTimeunit(time, unit)

.spadesTimes

spadesTimes()

checkTimeunit(unit, envir)

## S4 method for signature 'character,missing'
checkTimeunit(unit, envir)

## S4 method for signature 'character,environment'
checkTimeunit(unit, envir)

Arguments

unit

Character. One of the time units used in SpaDES or user defined time unit, given as the unit name only. See details.

envir

An environment. This is where to look up the function definition for the time unit. See details.

time

Numeric. With a unit attribute, indicating the time unit of the input numeric. See Details.

Format

An object of class character of length 6.

Details

Current pre-defined units are found within the spadesTimes() function. The user can define a new unit. The unit name can be anything, but the function definition must be of the form, "dunitName", e.g., dyear or dfortNight. The unit name is the part without the d and the function name definition includes the "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.

Because of R scoping, if envir is a simList environment, then this function will search there first, then up the current search() path. Thus, it will find a user defined or module defined unit before a SpaDEs unit. This means that a user can override the dyear given in SpaDES, for example, which is 365.25 days, with dyear <- function(x) lubridate::duration(dday(365))

If time has no units attribute, then it is assumed to be seconds.

Value

A numeric vector of length 1, with unit attribute set to "seconds".

Author(s)

Alex Chubaty & Eliot McIntire

Eliot McIntire

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.