A simple and reliable way to convert many different objects into a uniform
format for use within R.
try.xts()
and 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.
try.xts()
calls as.xts()
internally. See as.xts()
for available xts
methods and arguments for each coercible class. Since it calls as.xts()
,
you can add custom attributes as name = value
pairs in the same way. But
these custom attributes will not be copied back to the original object when
reclass()
is called.
The error
argument can be a logical value indicating whether an error
should be thrown (or fail silently), a character string allowing for custom
error error messages, or a function of the form f(x, ...)
that will be
called if the conversion fails.
reclass()
converts an object created by try.xts()
back to its original
class with all the original attributes intact (unless they were changed
after the object was converted to xts). The match.to
argument allows you
copy the index attributes (tclass
, tformat
, and tzone
) and
xtsAttributes()
from another xts object to the result. match.to
must
be an xts object with an index value for every observation in x
.
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 in R are not designed to return objects
matching the original object's class. It attempts to handle conversion and
reconversion transparently but it requires the original object must be
coercible to xts, the result of the function must have the same number of
rows as the input, and the object to be converted/reclassed must be the
first argument to the function being wrapped. Note that this function
hasn't been tested for robustness.
See the accompanying vignette for more details on the above usage.