Learn R Programming

ThomasJeffersonUniv (version 0.1.3)

asDifftime: Create Time Differences, Extended

Description

To create difftime object with additional time units 'months' and 'years'.

Usage

asDifftime(
  tim,
  units = names(timeUnits()),
  negative_do = stop(sQuote(deparse1(substitute(tim))), " has negative value!"),
  ...
)

Value

Function asDifftime returns a difftime object.

Arguments

tim

numeric or difftime object, similar usage as in function as.difftime

units

character scalar, similar usage as in function as.difftime, but with additional options 'months' and 'years'

negative_do

exception handling if input tim has negative element(s). Default is to stop

...

additional parameters, currently not in use

Details

Function asDifftime improves function as.difftime in terms that

  • If input tim is a difftime object, function units_difftime<- is called and the unit of tim is updated. In function as.difftime, tim is returned directly, i.e., parameter units is ignored

  • Time units 'months' and 'years' are supported, in addition to 'secs', 'mins', 'hours', 'days', 'weeks' supported in function as.difftime. Moreover, partial matching (via function match.arg) is allowed, while function as.difftime requires exact matching.

  • End user may choose to stop if tim has negative values. Function as.difftime does not check for negative tim.