[R] maptools, sunriset, POSIX timezones

Phil Taylor tabanid at gmail.com
Mon Jan 19 22:37:24 CET 2009


Hi ...

I wonder if anyone can provide some insight into why the first three 
examples using the sunriset function (appended below, with results) give 
the correct answer, but the fourth generates and error.

The first two use ISOdatetime with and without a time zone attribute, 
and the sunriset function returns the correct sunset time.

The third and fourth adds 10 seconds to the ISOdatetime (with and 
without the time zone attribute) but the function only works when the 
time zone is specified (example 3).

When I look at the objects (print or str) they appear the same, and when 
I check to see if they are equivalent (e.g.)

 > time.1 <- ISOdatetime(1970, 1, 1, 10, 0, 0) + 10
 > time.2 <- ISOdatetime(1970, 1, 1, 10, 0, 0, tz="GMT") + 10
 > time.1 == time.2
[1] TRUE

they appear to be the same.

I wonder if I am either missing something important, doing something 
improperly, or if there is a small bug somewhere.

I'm using windows Vista and R 2.8.1

Thanks,

Phil Taylor
ptaylor at resalliance.org

 > require(maptools)
 > Sys.setenv(TZ = "GMT")
 > location <- matrix(c(-80.1,42.5), nrow=1)

 > sunriset(location, ISOdatetime(1970, 1, 1, 10, 0, 0, tz="GMT"), 
direction="sunset", POSIXct.out=TRUE)
   day_frac                time
1 0.915226 1970-01-01 21:57:55

 > sunriset(location, ISOdatetime(1970, 1, 1, 10, 0, 0), 
direction="sunset", POSIXct.out=TRUE)
   day_frac                time
1 0.915226 1970-01-01 21:57:55

 > sunriset(location, ISOdatetime(1970, 1, 1, 10, 0, 0, tz="GMT") + 10, 
direction="sunset", POSIXct.out=TRUE)
   day_frac                time
1 0.915226 1970-01-01 21:57:55

 > sunriset(location, ISOdatetime(1970, 1, 1, 10, 0, 0) + 10, 
direction="sunset", POSIXct.out=TRUE)
Error in structure(.Internal(as.POSIXct(x, tz)), class = c("POSIXt", 
"POSIXct"),  :
         invalid 'tz' value




More information about the R-help mailing list