## rw1031 Version 1.3.1 (2001-08-31) ## > version ## _ ## platform i386-pc-mingw32 ## arch x86 ## os Win32 ## system x86, Win32 ## status ## major 1 ## minor 3.1 ## year 2001 ## month 08 ## day 31 ## language R ## The beav1 example in *help[R](plot.POSIXct)* shows two bugs. ## The first is a fundamental error in strptime. ## ## The second is two details in the construction of the example. ## ## strptime is not using the "%j" format correctly. This has the effect ## of wrapping the time in the beav1 example. Here is a simplified ## example in which we see that the day wraps. library(MASS) data(beav1) tmp <- beav1[90:93,] tmp attach(tmp) paste(day, time %/% 100, time %% 100) strptime(paste(day, time %/% 100, time %% 100), "%j %H %M") ## note that the times wrap and the times on both days 346 and 347 are ## mapped to "1900-01-01" ## Including the year in the format gets the right answer, with two ## different days appearing in the result. strptime(paste(1990, day, time %/% 100, time %% 100), "%Y %j %H %M") detach("tmp") ## > tmp <- beav1[90:93,] ## > tmp ## day time temp activ ## 90 346 2340 36.93 0 ## 91 346 2350 36.83 0 ## 92 347 0 36.93 0 ## 93 347 10 36.83 0 ## > attach(tmp) ## > paste(day, time %/% 100, time %% 100) ## [1] "346 23 40" "346 23 50" "347 0 0" "347 0 10" ## > strptime(paste(day, time %/% 100, time %% 100), ## + "%j %H %M") ## [1] "1900-01-01 23:40:00" "1900-01-01 23:50:00" "1900-01-01 00:00:00" ## [4] "1900-01-01 00:10:00" ## > strptime(paste(1990, day, time %/% 100, time %% 100), ## + "%Y %j %H %M") ## [1] "1990-12-12 23:40:00" "1990-12-12 23:50:00" "1990-12-13 00:00:00" ## [4] "1990-12-13 00:10:00" ## > detach("tmp") ## I think this would be better for the example ## I am making two changes. ## 1. Add the year 1990 ## 2. use temporary variable name instead of "time". "time" persists ## after detaching "beav1", hence it had precedence when I reattached ## beav1 and the arithmetic using time generated an error. attach(beav1) tmp.time <- strptime(paste(1900, day, time %/% 100, time %% 100), "%Y %j %H %M") plot(tmp.time, temp, type="l") # axis at 4-hour intervals. detach("beav1") -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 31 Oct 2001 rmh@surfer.sbm.temple.edu wrote:> ## rw1031 Version 1.3.1 (2001-08-31) > > ## > version > ## _ > ## platform i386-pc-mingw32 > ## arch x86 > ## os Win32 > ## system x86, Win32 > ## status > ## major 1 > ## minor 3.1 > ## year 2001 > ## month 08 > ## day 31 > ## language R > > ## The beav1 example in *help[R](plot.POSIXct)* shows two bugs. > ## The first is a fundamental error in strptime.In your OS's implementation of strptime, not the R code ....> ## > ## The second is two details in the construction of the example. > ## > ## strptime is not using the "%j" format correctly. This has the effect > ## of wrapping the time in the beav1 example. Here is a simplified > ## example in which we see that the day wraps. > > library(MASS) > data(beav1) > tmp <- beav1[90:93,] > tmp > attach(tmp) > paste(day, time %/% 100, time %% 100) > strptime(paste(day, time %/% 100, time %% 100), > "%j %H %M") > > ## note that the times wrap and the times on both days 346 and 347 are > ## mapped to "1900-01-01"Well, I don't get either of those: [1] "2001-12-12 23:40:00" "2001-12-12 23:50:00" "2001-12-13 00:00:00" [4] "2001-12-13 00:10:00" It would be helpful to give the incorrect output that your system gives. In the output below I see no evidence of `the times wrap'. Using the wrong day seems to be a bug in glibc's strptime, but you need to unclass the strptime result to see this. (I do see the strptime bug on RH6.2 Linux, where the day field is ignored.)> ## Including the year in the format gets the right answer, with two > ## different days appearing in the result.Yes, but that was not the intention in the original (real) example, where the year was not specified.> strptime(paste(1990, day, time %/% 100, time %% 100), > "%Y %j %H %M") > > detach("tmp") > > ## > tmp <- beav1[90:93,] > ## > tmp > ## day time temp activ > ## 90 346 2340 36.93 0 > ## 91 346 2350 36.83 0 > ## 92 347 0 36.93 0 > ## 93 347 10 36.83 0 > ## > attach(tmp) > ## > paste(day, time %/% 100, time %% 100) > ## [1] "346 23 40" "346 23 50" "347 0 0" "347 0 10" > ## > strptime(paste(day, time %/% 100, time %% 100), > ## + "%j %H %M") > ## [1] "1900-01-01 23:40:00" "1900-01-01 23:50:00" "1900-01-01 00:00:00" > ## [4] "1900-01-01 00:10:00" > ## > strptime(paste(1990, day, time %/% 100, time %% 100), > ## + "%Y %j %H %M") > ## [1] "1990-12-12 23:40:00" "1990-12-12 23:50:00" "1990-12-13 00:00:00" > ## [4] "1990-12-13 00:10:00" > ## > detach("tmp") > > > ## I think this would be better for the example > ## I am making two changes. > > ## 1. Add the year 1990(You used 1900 below!)> > ## 2. use temporary variable name instead of "time". "time" persists > ## after detaching "beav1", hence it had precedence when I reattached > ## beav1 and the arithmetic using time generated an error. > > attach(beav1) > tmp.time <- strptime(paste(1900, day, time %/% 100, time %% 100), > "%Y %j %H %M") > plot(tmp.time, temp, type="l") # axis at 4-hour intervals. > detach("beav1")Again, the need was to use `time' after the detach. This only occurred because you did not remove the variable your system created incorrectly. I will change this to work around a system-specific bug. I'll pass on to the Windows maintainer fixing the strptime code used on that platform. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 31 Oct 2001, Peter Dalgaard BSA wrote:> ripley@stats.ox.ac.uk writes: > > > > ## The beav1 example in *help[R](plot.POSIXct)* shows two bugs. > > > ## The first is a fundamental error in strptime. > > > > In your OS's implementation of strptime, not the R code .... > ... > > It would be helpful to give the incorrect output that your system gives. > > In the output below I see no evidence of `the times wrap'. Using the > > wrong day seems to be a bug in glibc's strptime, but you need to unclass > > the strptime result to see this. (I do see the strptime bug on RH6.2 > > Linux, where the day field is ignored.) > > RH7.1 too.I've located the problem, which boils down to inaccuracies in the following in man strptime: The GNU libc implementation does not touch those fields which are not directly initialized. Exceptions are the tm_wday and tm_yday elements which are recomputed if any of the year, month, or date elements changed. As RMH's example shows, it does touch the tm_mon and tm_mday fields if the year is specified (even if unchanged) but not quite always. I am writing a workaround for R-devel. Yet another system-specific problem with the date-time code! Brian -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Where is the strptime bug happening? I am seeing it on W95 W98 W2000 running Rterm under ntemacs 21.1 with ESS 5.1.19 and using cygwin 2001/08/31 15:52:16 Starting cygwin install, version 2.78.2.3 Is strptime using the bash from my system? or is it using functions that are included with R? R defaulted to 1900 when I didn't specify a year. The 1990 came from the help(beav1). When I explicitly place a year in the file, either the 1990 inidcated in the help(beav1) file or the 1900 chosen to match the default, then R gives me times consistent with the input.> tmp <- beav1[90:93,] > tmpday time temp activ 90 346 2340 36.93 0 91 346 2350 36.83 0 92 347 0 36.93 0 93 347 10 36.83 0> attach(tmp) > strptime(paste(day, time %/% 100, time %% 100), "%j %H %M")[1] "1900-01-01 23:40:00" "1900-01-01 23:50:00" "1900-01-01 00:00:00" [4] "1900-01-01 00:10:00"> strptime(paste(1900, day, time %/% 100, time %% 100), "%Y %j %H %M")[1] "1900-12-12 23:40:00" "1900-12-12 23:50:00" "1900-12-13 00:00:00" [4] "1900-12-13 00:10:00"> strptime(paste(1990, day, time %/% 100, time %% 100), "%Y %j %H %M")[1] "1990-12-12 23:40:00" "1990-12-12 23:50:00" "1990-12-13 00:00:00" [4] "1990-12-13 00:10:00">Rich -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 31 Oct 2001, Rich Heiberger wrote:> Where is the strptime bug happening? I am seeing it on W95 W98 W2000 > running Rterm under ntemacs 21.1 with ESS 5.1.19 and using cygwin > 2001/08/31 15:52:16 Starting cygwin install, version 2.78.2.3It is happening on all glibc-based systems. R on Windows uses glibc to replace the missing functionality here.> Is strptime using the bash from my system? or is it using functions > that are included with R?The second.> R defaulted to 1900 when I didn't specify a year. The 1990 came from > the help(beav1). > > When I explicitly place a year in the file, either the 1990 inidcated > in the help(beav1) file or the 1900 chosen to match the default, then > R gives me times consistent with the input.Yes, that's the bug. According to the docs it should fail in all the cases (which would be silly), but the code has at least two internal logical mistakes. It will be fixed in the next release.> > tmp <- beav1[90:93,] > > tmp > day time temp activ > 90 346 2340 36.93 0 > 91 346 2350 36.83 0 > 92 347 0 36.93 0 > 93 347 10 36.83 0 > > attach(tmp) > > strptime(paste(day, time %/% 100, time %% 100), "%j %H %M") > [1] "1900-01-01 23:40:00" "1900-01-01 23:50:00" "1900-01-01 00:00:00" > [4] "1900-01-01 00:10:00" > > strptime(paste(1900, day, time %/% 100, time %% 100), "%Y %j %H %M") > [1] "1900-12-12 23:40:00" "1900-12-12 23:50:00" "1900-12-13 00:00:00" > [4] "1900-12-13 00:10:00" > > strptime(paste(1990, day, time %/% 100, time %% 100), "%Y %j %H %M") > [1] "1990-12-12 23:40:00" "1990-12-12 23:50:00" "1990-12-13 00:00:00" > [4] "1990-12-13 00:10:00" > > > > > Rich >-- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._