Openxlsx convertToDateTime omits time with big dataset

Viewed 862

I am trying to use openxlsx to read large excel files with time series data. I found that convertToDateTime starts omitting the time if the numeric vector argument exceeds a certain amount of elements. My code looks like this:

ts <- readWorkbook(my.wb, sheet = as.character(r[["dSheet"]]), 
                startRow = 2, cols = 1, 
                colNames=FALSE, detectDates=FALSE)
colnames(ts) <- c("dt")
> head(convertToDateTime(ts$dt[1:30830]))
[1] "2016-11-23 15:20:00 MST" "2016-11-23 15:24:59 MST"
[3] "2016-11-23 15:30:00 MST" "2016-11-23 15:34:59 MST"
[5] "2016-11-23 15:40:00 MST" "2016-11-23 15:45:00 MST"

> head(convertToDateTime(ts$dt[1:30840]))
[1] "2016-11-23 MST" "2016-11-23 MST" "2016-11-23 MST" "2016-11-23 MST"
[5] "2016-11-23 MST" "2016-11-23 MST"

Side question: If you look at element #2 (2016-11-23 15:24:59) in my original code, this should actually be 15:25. If there's a simple way to fix this please let me know...

Here's a working example:

>library("openxlsx")
>dates <- runif(31000, 41000, 42000)
>head(convertToDateTime(dates[1:5000]))

[1] "2013-05-29 09:34:28 MDT" "2014-07-01 03:52:13 MDT"
[3] "2012-06-02 09:27:47 MDT" "2012-05-06 13:42:04 MDT"
[5] "2014-09-26 04:50:36 MDT" "2013-10-26 03:14:00 MDT"

> head(convertToDateTime(dates[1:10000]))
[1] "2013-05-29 MDT" "2014-07-01 MDT" "2012-06-02 MDT" "2012-05-06 MDT"
[5] "2014-09-26 MDT" "2013-10-26 MDT"

Is there a fix for this behavior or would you recommend to try a completely different approach (implement conversion)?

Thank you in advance for your help!

1 Answers
Related