I’m getting unexpected output from the all.equal method in R, specifically the implementation for POSIXct, all.equal.POSIXct.
t <- Sys.time()
isTRUE(all.equal(t, t+1))
returns TRUE, and
isTRUE(all.equal(t, t+1, scale = 1))
returns FALSE.
However, if you look at the definition of all.equal.POSIXct, you can see that the scale parameter has a default of 1:
> all.equal.POSIXct
function (target, current, ..., scale = 1)
{
check_tzones(target, current)
NextMethod("all.equal")
}
<bytecode: 0x22eac90>
<environment: namespace:base>
You get the same results if you explicitly call all.equal.POSIXct instead of all.equal.
Why isn’t the default parameter scale = 1 being picked up in the first call to all.equal.POSIXct? Am I doing something wrong, or have I fundamentally misunderstood something, or is this a bug?
Thanks in advance for any help.
I’m going out on a slight limb here, but I think you have discovered a bug.
Here is my suggested fix:
Then the function gives the correct results:
This is why the existing code doesn’t work:
The definition for
all.equalis:Notice that there are three arguments:
target,currentand....Thus, whenever you use
NextMethodthese three arguments will be passed to the next method.However, in the case of
all.equal.POSIXctthere is an additional argumentscale=, but this doesn’t get passed on either implicitly or explicitly.