Conversion functions to coerce data objects of
arbitrary classes to class
xts and back, without
losing any attributes of the original format.
as.xts(x, ...) xtsible(x)
try.xts(x, ..., error = TRUE) reclass(x, match.to, error = FALSE, ...)
An S3 object of class
In the case of
reclass, the object
returned will be of the original class as identified by
data object to convert. See details for supported types
xts object whose attributes will be passed to
error handling option. See Details.
additional parameters or attributes
Jeffrey A. Ryan
A simple and reliable way to convert many different objects into a uniform format for use within R.
It is possible with a call to
convert objects of class
xtsible safely checks whether an object can be converted to
xts object; returning TRUE on success and FALSE
The help file
as.xts.methods lists all available
xts methods and arguments specific to each coercible type.
Additional name=value pairs may be passed to the function
to be added to the new object. A special print.xts method
will assure that the attributes are hidden from view, but will
be available via R's standard
attr function, as well
The returned object will preserve all relevant attribute/slot
data within itself, allowing for temporary conversion to use
zoo and xts compatible methods. A call to
returns the object to its original class, with all original
attributes intact - unless otherwise changed.
It should be obvious, but any attributes added via the ... argument will not be carried back to the original data object, as there would be no available storage slot/attribute.
Reclass is designed for top-level use, where it is
desirable to have the object returned from an arbitrary
function in the same class as the object passed in. Most
functions within R are not designed to return objects
matching the original object's class. While this tool is
highly experimental at present, it attempts to handle
conversion and reconversion transparently. The caveats are
that the original object must be coercible to
the returned object must be of the same row length as the
original object, and that the object to reconvert to is
the first argument to the function being wrapped.
reclass are functions that enable
external developers access to the reclassing tools within
xts to help speed development of time-aware functions,
as well as provide a more robust and seemless end-user experience,
regardless of the end-user's choice of data-classes.
error argument to try.xts accepts a logical value,
indicating where an error should be thrown, a character string
allowing for custom error messages to be displayed, or
a function of the form
f(x, ...), to be called
upon construction error.
See the accompanying vignette for more details on the above usage and the package in general.