Extraction of POSIXlt component runs fine in R 3.4.4, but errors in R 3.5.0. Why?

  • A+
Category:Languages

1) R version 3.4.4 (2018-03-15)

my.timedate <- as.POSIXlt('2016-01-01 16:00:00')   # print(attributes(my.timedate))   print(my.timedate[['hour']])    [1] 16 

2) R version 3.5.0 (2018-04-23)

my.timedate <- as.POSIXlt('2016-01-01 16:00:00')   # print(attributes(my.timedate))   print(my.timedate[['hour']])  

Error in FUN(X[[i]], ...) : subscript out of bounds

 


I think that is a known change in R 3.5.0 where the list elements of a POSIXlt need to be unpackaged explicitly. Using R 3.5.0:

edd@rob:~$ docker run --rm -ti r-base:3.5.0 /                R -q -e 'print(unclass(as.POSIXlt("2016-01-01 16:00:00")[["hour"]])' > print(unclass(as.POSIXlt("2016-01-01 16:00:00"))[["hour"]]) [1] 16 >  >  edd@rob:~$  

whereas with R 3.4.* one does not need the unclass() as you showed:

edd@rob:~$ docker run --rm -ti r-base:3.4.3 /                R -q -e 'print(as.POSIXlt("2016-01-01 16:00:00")[["hour"]])' > print(as.POSIXlt("2016-01-01 16:00:00")[["hour"]]) [1] 16 >  >  edd@rob:~$  

I don't find a corresponding NEWS file entry though so not entirely sure if it is on purpose...

Edit: As others have noted, the corresponding NEWS entry is the somewhat opaque

* Single components of "POSIXlt" objects can now be extracted and   replaced via [ indexing with 2 indices. 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: