The type nanoduration
is a length of time (implemented as
an S4 class) with nanosecond precision. It is a count of
nanoseconds and may be negative. The expected arithmetic
operations are provided, including sequence generation.
nanoduration(hours = 0L, minutes = 0L, seconds = 0L, nanoseconds = 0L)# S4 method for character
as.nanoduration(x)
# S4 method for integer64
as.nanoduration(x)
# S4 method for numeric
as.nanoduration(x)
# S4 method for integer
as.nanoduration(x)
# S4 method for difftime
as.nanoduration(x)
# S4 method for `NULL`
as.nanoduration(x)
# S4 method for missing
as.nanoduration(x)
# S4 method for nanoduration
show(object)
# S4 method for nanoduration
print(x, quote = FALSE, ...)
# S3 method for nanoduration
format(x, ...)
# S3 method for nanoduration
as.integer64(x, ...)
# S4 method for nanoduration
as.character(x)
# S4 method for nanoduration
is.na(x)
# S4 method for nanoduration,nanoduration
-(e1, e2)
# S4 method for nanoduration,integer64
-(e1, e2)
# S4 method for nanoduration,integer
-(e1, e2)
# S4 method for nanoduration,numeric
-(e1, e2)
# S4 method for nanoduration,difftime
-(e1, e2)
# S4 method for nanoduration,ANY
-(e1, e2)
# S4 method for nanotime,nanoduration
-(e1, e2)
# S4 method for nanotime,difftime
-(e1, e2)
# S4 method for integer64,nanoduration
-(e1, e2)
# S4 method for integer,nanoduration
-(e1, e2)
# S4 method for numeric,nanoduration
-(e1, e2)
# S4 method for difftime,nanoduration
-(e1, e2)
# S4 method for ANY,nanoduration
-(e1, e2)
# S4 method for nanoduration,ANY
+(e1, e2)
# S4 method for nanoduration,nanoduration
+(e1, e2)
# S4 method for nanoduration,integer64
+(e1, e2)
# S4 method for nanoduration,numeric
+(e1, e2)
# S4 method for nanoduration,difftime
+(e1, e2)
# S4 method for nanotime,nanoduration
+(e1, e2)
# S4 method for nanotime,difftime
+(e1, e2)
# S4 method for nanoduration,nanotime
+(e1, e2)
# S4 method for difftime,nanotime
+(e1, e2)
# S4 method for nanoival,nanoduration
+(e1, e2)
# S4 method for nanoival,nanoduration
-(e1, e2)
# S4 method for nanoduration,nanoival
+(e1, e2)
# S4 method for nanoival,difftime
+(e1, e2)
# S4 method for nanoival,difftime
-(e1, e2)
# S4 method for difftime,nanoival
+(e1, e2)
# S4 method for integer64,nanoduration
+(e1, e2)
# S4 method for numeric,nanoduration
+(e1, e2)
# S4 method for difftime,nanoduration
+(e1, e2)
# S4 method for nanoduration,numeric
*(e1, e2)
# S4 method for nanoduration,integer64
*(e1, e2)
# S4 method for numeric,nanoduration
*(e1, e2)
# S4 method for integer64,nanoduration
*(e1, e2)
# S4 method for nanoduration,nanoduration
/(e1, e2)
# S4 method for nanoduration,integer64
/(e1, e2)
# S4 method for nanoduration,numeric
/(e1, e2)
# S4 method for nanoduration,ANY
Arith(e1, e2)
# S4 method for nanoduration,character
Compare(e1, e2)
# S4 method for character,nanoduration
Compare(e1, e2)
# S4 method for nanoduration,ANY
Compare(e1, e2)
# S4 method for nanoduration
abs(x)
# S4 method for nanoduration
sign(x)
# S4 method for nanoduration
sum(x, ..., na.rm = FALSE)
# S4 method for nanoduration
min(x, ..., na.rm = FALSE)
# S4 method for nanoduration
max(x, ..., na.rm = FALSE)
# S4 method for nanoduration
range(x, ..., na.rm = FALSE)
# S4 method for nanoduration
[[(x, i, j, ..., drop = FALSE)
# S4 method for nanoduration,numeric
[(x, i, j, ..., drop = FALSE)
# S4 method for nanoduration,logical
[(x, i, j, ..., drop = FALSE)
# S4 method for nanoduration,character
[(x, i, j, ..., drop = FALSE)
# S4 method for nanoduration,ANY
[(x, i, j, ..., drop = FALSE)
# S4 method for nanoduration,ANY,ANY,ANY
[(x, i, j, ...) <- value
# S3 method for nanoduration
c(...)
NA_nanoduration_
A nanoduration object
An object of class nanoduration
of length 1.
number of hours
number of minutes
number of seconds
number of nanoseconds
a nanoduration
object
argument for method show
indicates if the output of print
should be
quoted
further arguments passed to or from methods.
Operand of class nanoival
Operand of class nanoival
if TRUE
NA values are removed for the
computation
index specifying elements to extract or replace.
Required for [
signature but ignored here
Required for [
signature but ignored here
argument for nanoduration-class
Dirk Eddelbuettel
Leonardo Silvestri
A nanoduration
can be constructed with the function
as.nanoduration
which can take the types integer64
,
integer
and numeric
(all indicating the count in
nanosecond units) or the type character
.
It can also be constructed by specifying with individual arguments
the hours, minutes, seconds and nanoseconds with a call to
nanoduration
.
A nanoduration
is displayed as hours, minutes, seconds and
nanoseconds like this: 110:12:34.123_453_001
. The nanosecond
precision displayed is adjusted as necessary, so e.g. 1 second is
displayed as 00:00:01
.
nanotime
## constructors:
nanoduration(hours=10, minutes=3, seconds=2, nanoseconds=999999999)
as.nanoduration("10:03:02.999_999_999")
as.nanoduration(36182999999999)
## arithmetic:
as.nanoduration(10e9) - as.nanoduration(9e9)
as.nanoduration(10e9) + as.nanoduration(-9e9)
as.nanoduration("24:00:00") / 2
as.nanoduration("24:00:00") / as.nanoduration("12:00:00")
## comparison:
as.nanoduration("10:03:02.999_999_999") == 36182999999999
as.nanoduration("10:03:02.999_999_999") > as.nanoduration("10:03:02.999_999_998")
as.nanoduration("10:03:02.999_999_998") < "10:03:02.999_999_999"
Run the code above in your browser using DataLab