The values are stored as a difftime vector with a custom class, and always with "seconds" as unit for robust coercion to numeric. Supports construction from time values, coercion to and from various data types, and formatting. Can be used as a regular column in a data frame.
hms() is a high-level constructor that accepts second, minute, hour and day components
as numeric vectors.
new_hms() is a low-level constructor that only checks that its input has the correct base type, numeric.
is_hms() checks if an object is of class
as_hms() forwards to
hms(seconds = NULL, minutes = NULL, hours = NULL, days = NULL) new_hms(x = numeric()) is_hms(x) as_hms(x) # S3 method for hms as.POSIXct(x, ...) # S3 method for hms as.POSIXlt(x, ...) # S3 method for hms as.character(x, ...) # S3 method for hms format(x, ...) # S3 method for hms print(x, ...)
|seconds, minutes, hours, days||
Time since midnight. No bounds checking is performed.
additional arguments to be passed to or from methods.
hms, all arguments must have the same length or be
NULL. Odd combinations (e.g., passing only
hours but not
minutes) are rejected.
hms(56, 34, 12)#> 12:34:56hms()#> hms()new_hms(as.numeric(1:3))#> 00:00:01 #> 00:00:02 #> 00:00:03# Supports numeric only! try(new_hms(1:3))#> Error : `x` must be a vector with type <double>. #> Instead, it has type <integer>.as_hms(1)#> 00:00:01as_hms("12:34:56")#> 12:34:56as_hms(Sys.time())#> 23:29:07.069104as.POSIXct(hms(1))#>  "1970-01-01 00:00:01 UTC"data.frame(a = hms(1))#> a #> 1 00:00:01d <- data.frame(hours = 1:3) d$hours <- hms(hours = d$hours) d#> hours #> 1 01:00:00 #> 2 02:00:00 #> 3 03:00:00