[Rd] as.POSIXct behaviour

Arunkumar Srinivasan arunkumar.sriniv at gmail.com
Thu Mar 9 01:29:00 CET 2017


Dear R-devel, I have tested the code below on R v3.3.2 and v3.3.3 on
Mac and Windows.

x <- c("2017-01-01 05:00:02", "2017-01-02 03 :M:00") # note the ‘ :M’
in 2nd value
as.POSIXct(x)
# [1] "2017-01-01 GMT" "2017-01-02 GMT”

The time info is lost on the first index as well. And it happens *silently*.

On the other hand, if I do:

lapply(x, as.POSIXct)
# [[1]]
# [1] "2017-01-01 05:00:02 GMT"
#
# [[2]]
# [1] "2017-01-02 GMT”

A list is returned, but values are as I’d expect. Would it be possible
to retain the time info with as.POSIXct(x) directly as well? If not,
what’s the rationale? In addition, I think a warning message that some
malformed timestamps were found would be very useful.

Thank you,
Arun.



More information about the R-devel mailing list