[R] Problem with all.equal and POSIXt.
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-12fortunes_1.3-7 MASS_7.3-6 loaded via a namespace (and not attached): [1] tools_2.11.1 ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with all.equal and POSIXt.
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: 0x06037088 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. 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.tur...@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 ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with all.equal and POSIXt.
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: 0x06037088 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 Turnerr.tur...@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-12fortunes_1.3-7 MASS_7.3-6 loaded via a namespace (and not attached): [1] tools_2.11.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with all.equal and POSIXt.
On 13/09/2010, at 3:07 PM, Peter Ehlers wrote: SNIP 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). Well, I ***would*** call it a bug. The all.equal() function is confusing the length of x as a POSIXlt object (i.e. the length of its list components) with the length of the (well hidden) list structure of x (i.e. 9). This is the wrong thing to do, so it's a bug. I notice that there is an all.equal.POSIXct() method. Maybe there should also be an as.equal.POSIXlt() method --- which would just coerce its argument to POSIXct, and then do NextMethod(). But maybe there's a Good Reason why R Core did not implement an as.equal.POSIXlt() method --- i.e. it's dangerous to apply all.equa1() to POSIXlt objects. Can't think why this should be, but. cheers, Rolf ## Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ## __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.