Unexpected output from all.equal.POSIXct

posixct, r

Solution

I'm going out on a slight limb here, but I think you have discovered a bug.

Here is my suggested fix:

all.equal.POSIXct <- function (target, current, ..., scale = 1) {
  check_tzones(target, current)
  NextMethod("all.equal", scale=scale, ...)
}

Then the function gives the correct results:

all.equal(t, t+1)
[1] "Mean scaled difference: 1"

all.equal(t, t+1, scale=10)
[1] "Mean scaled difference: 0.1"

This is why the existing code doesn't work:

The definition for `all.equal` is:

all.equal <- function (target, current, ...) UseMethod("all.equal")

Notice that there are three arguments: `target`, `current` and `...`.

Thus, whenever you use `NextMethod` these three arguments will be passed to the next method.

However, in the case of `all.equal.POSIXct` there is an additional argument `scale=`, but this doesn't get passed on either implicitly or explicitly.

Problem

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.

Original source