The DTSg class is the working horse of the package. It is an
R6Class and offers an S3 interface in addition to its
native R6 interface. In the usage sections of the documentation only the S3
interface is shown, however, the examples always show both possibilities.
Generally, they are very similar anyway. While the R6 interface always has
the object first and the method is selected with the help of the $
operator (for instance, x$cols()), the S3 interface always has the
method first and the object as its first argument (for instance,
cols(x)). An exception is the new method. It is not an S3
method, but an abused S4 constructor with the character string "DTSg"
as its first argument. Regarding the R6 interface, the DTSg class
generator has to be used to access the new method with the help of
the $ operator.
new(Class, values, ID = "", parameter = "", unit = "", variant = "",
aggregated = FALSE, fast = FALSE, swallow = FALSE)A character string. Must be "DTSg" in order to create a
DTSg object. Otherwise a different object may or may not be created
(S4 constructor only).
A data.frame or object inherited from class
data.frame, for instance,
data.table. Its first column must be of class
POSIXct or coercible to it. It serves as the object's time
index and is renamed to .dateTime.
A character string specifying the ID (name) of the time series.
A character string specifying the parameter of the time series.
A character string specifying the unit of the time series.
A character string specifying further metadata of the time
series, for instance, "min" to point out that it is a time series of
lower bound measurements.
A logical signalling how the timestamps of the series have
to be interpreted: as snap-shots (FALSE) or as periods between
subsequent timestamps (TRUE).
A logical signalling if all rows (FALSE) or only the first
1000 rows (TRUE) shall be used to check the object's integrity and
for the automatic detection of the time series' periodicity.
A logical signalling if the object provided through the
values argument shall be “swallowed” by the DTSg
object, i.e., no copy of the data shall be made. This is generally more
ressource efficient, but only works if the object provided through the
values argument is a data.table. Be warned,
however, that if the creation of the DTSg object fails for some
reason, the first column of the provided
data.table might have been coerced to
POSIXct and keyed (see setkey for
further information). Furthermore, all references to the “swallowed”
data.table in the global environment are removed
upon successfull creation of a DTSg object.
Returns a DTSg object.
An object of class R6ClassGenerator of length 24.
A DTSg object has the following methods:
aggregate: See aggregate for further
information.
alter: See alter for further information.
colapply: See colapply for further information.
cols: See cols for further information.
merge: See merge for further information.
nas: See nas for further information.
plot: See plot for further information.
refresh: See refresh for further information.
rollapply: See rollapply for further
information.
summary: See summary for further information.
values: See values for further information.
A DTSg object has the following fields or properties as they are often
called. They are implemented through so called active bindings, which means
that they can be accessed and actively set with the help of the $
operator (for instance, x$ID gets the value of the ID field
and x$ID <- "River Flow" sets its value). Please note that fields are
always modified in place, i.e., no clone (copy) of the object is made
beforehand. See clone for further information. Some of the
fields are read-only though:
aggregated: Same as aggregated argument.
fast: Same as fast argument.
ID: Same as ID argument. It is used as the title of
plots.
parameter: Same as parameter argument. It is used as
the label of the primary axis of plots.
periodicity: A difftime object for a regular
and a character string for an irregular DTSg object describing
its periodicity or containing "unrecognised" in case it could not
be detected (read-only).
regular: A logical signalling if all lags in seconds between
subsequent timestamps are the same (TRUE) or if some are
different (FALSE). A, for instance, monthly time series is
considered irregular in this sense (read-only).
timestamps: An integer showing the total number of timestamps of the time series (read-only).
timezone: A character string containing the time zone of the time series (read-only).
unit: Same as unit argument. It is added to the label
of the primary axis of plots if the parameter field is set.
variant: Same as variant argument. It is added to the
label of the primary axis of plots if the parameter field is set.
The parameter, unit and variant fields are especially useful for time series with one variable (value column) only.
The behaviour of DTSg objects can be customised with the help of the
following option. See options for further information:
DTSgClone: A logical specifying if DTSg objects are,
by default, modified in place (FALSE) or if a clone (copy) is
made beforehand (TRUE).
R6Class, data.frame,
data.table, POSIXct,
setkey, difftime,
clone, options, list
# NOT RUN {
# new DTSg object
## R6 constructor
DTSg$new(values = flow, ID = "River Flow")
## S4 constructor
new(Class = "DTSg", values = flow, ID = "River Flow")
# }
Run the code above in your browser using DataLab