[R] Problem with all.equal and POSIXt.
Peter Ehlers
ehlers at ucalgary.ca
Mon Sep 13 05:07:25 CEST 2010
On 2010-09-12 20:32, Joshua Wiley wrote:
> I get the same error. On debugging, after the 10th iteration (~1,375
> lines after the all.equal(x, x) call), I get:
>
> exiting from: all.equal(target[[i]], current[[i]], check.attributes =
> check.attributes,
> ...)
> debugging in: all.equal(target[[i]], current[[i]], check.attributes =
> check.attributes,
> ...)
> debug: UseMethod("all.equal")
> Browse[4]> ls() # so it shows "current" and "target", but...
> [1] "current" "target"
> Browse[4]> current # when I try to look at it
> Error in current[[i]] : subscript out of bounds
> Browse[4]> target
> Error in target[[i]] : subscript out of bounds
> Browse[4]> getAnywhere(current)
> no object named 'current' was found
> Browse[4]> environment()
> <environment: 0x0000000006037088>
> Browse[4]> exists(current)
> Error in current[[i]] : subscript out of bounds
> In addition: Warning message:
> In exists(current) : restarting interrupted promise evaluation
>
> Which is utterly out of my league, but perhaps useful to others. At
> the least, this seems an odd error message to give if all.equal()
> cannot handle that type of object.
The 'problem' is with the structure of the POSIXlt object.
Try this:
x[[4]] # ok
x[[9]] # ok
x[[10]] # subcript out of bounds
attributes(x)
Note that the 'names' attribute has 9 components which are
displayed by x[[i]].
all.equal(x,x) calls all.equal.list(x,x) which compares
target[[i]] to current[[i]]. The problem is that it's natural
to assume that target[[i]] refers to the ith element of x when
in fact it refers to the ith name (e.g. weekday for i==7) for
all elements of x. Since there are only 9 components in
attr(x, 'name'), we run out of subscripts when we look for
the 10th component.
I'm not sure that I would call this a bug, but it would seem
helpful to return an appropriate error message or to coerce to
POSIXct. Note that
all.equal(as.POSIXct(x), as.POSIXct(x))
yields TRUE, as does using as.Date(x).
-Peter Ehlers
>
> My system:
> R version 2.11.1 (2010-05-31)
> x86_64-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> loaded via a namespace (and not attached):
> [1] grid_2.11.1 tools_2.11.1
>
>
> Josh
>
> On Sun, Sep 12, 2010 at 6:28 PM, Rolf Turner<r.turner at auckland.ac.nz> wrote:
>>
>> I'm getting an error when applying all.equal() to objects of
>> class POSIXt.
>>
>> E.g.
>>
>> x<- strptime(rep("2007-02-12",10),format="%Y-%m-%d")
>> all.equal(x,x)
>> Error in target[[i]] : subscript out of bounds
>>
>> The object seems to have to be of double-digit length to trigger the
>> error. E.g.
>>
>> all.equal(x[1:9],x[1:9])
>>
>> returns TRUE.
>>
>> I did a cursory search of the r-help pages and found no reference to this
>> problem.
>>
>> Is this a bug, or am I missing something?
>>
>> cheers,
>>
>> Rolf Turner
>>
>> P. S.:> sessionInfo()
>> R version 2.11.1 (2010-05-31)
>> x86_64-apple-darwin9.8.0
>>
>> locale:
>> [1] en_NZ.UTF-8/en_NZ.UTF-8/C/C/en_NZ.UTF-8/en_NZ.UTF-8
>>
>> attached base packages:
>> [1] datasets utils stats graphics grDevices methods base
>>
>> other attached packages:
>> [1] misc_0.0-12 fortunes_1.3-7 MASS_7.3-6
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.11.1
>>
More information about the R-help
mailing list