One of the kool things about R is if I type the function name I get to see the implementation. But this one is confusing me, recursively:
> library(xts)
> align.time
function (x, ...)
{
UseMethod("align.time")
}
<environment: namespace:xts>
x is an XTS object, so doesn't that mean it will call the XTS align.time method... but that is what I'm looking at! (Typing xts::align.time
gives exactly the same response.)
The short answer is that you are looking for the function
xts:::align.time.xts
.The longer answer is that you can find which methods exist for
align.time
by callingmethods
:This tells you that there is a method
align.time.xts
that is not exported from the namespace. At this point you can probably guess that it can be found in packagexts
, but you can confirm that withgetAnywhere
:You can, of course, read the source directly, but since the function is not exported, you need to use
package:::function
(i.e. three colons):align.time()
is exported from the xts namespace, soxts::align.time
andalign.time
are the same thing. You need to note that there is analign.time()
method for objects of class"xts"
provided in the package and that is not exported from the namespace (it is just registered as an S3 method):It is this method that is being called when you pass an
"xts"
object toalign.time()
.When you call
align.time()
UseMethod()
sets up the search for and call of the appropriate"align.time"
method, if available, for the class of object supplied as the first argument.UseMethod
is doing exactly what you think it is doing, you have just confused yourself by looking at the same function (the generic) in two different ways.