3

I was trying to create a sequence of dates using the following code:

seq(from = as.POSIXct("2008-01-10 21:20:00 GMT",
                                            origin = "1970-01-01 00:00:00",
                                            format = "%Y-%m-%d %H:%M:%S"),
        by = 1, # Code won't hit the error for by values > 3, successfully run for values >=9
        to = as.POSIXct("2198-02-27 08:00:00",
                                        origin = "1970-01-01 00:00:00",
                                        format = "%Y-%m-%d %H:%M:%S"))

# This causes the following R error: 
# Error in seq.POSIXt(from = as.POSIXct("2008-01-10 21:20:00 GMT", origin = ”1970-01-01 00:00:00",  : 
# negative length vectors are not allowed

I accept that I'm doing something a little odd here, essentially trying to create a vector of about 198*365*24*60*60 = 6244128000, but I would in that case simply expect it to to take a long time. Is the error message simply inaccurate?

Having dug a little deeper I found that the error stems from seq.int() which is used by seq.POSIXt() (I think the error occurs around line 68 of seq.POSIXt()). Additionally this code works for "by" values that are greater than 3 (although it does understandably hit memory issues). I managed to get it to complete and provide a sequence for '"by" values greater than or equal to 9.

Thanks for your time. This is my first StackOverflow question so I'm sorry if I've failed to adhere to the etiquette in anyway! All help finding out what is going wrong is greatly appreciated.

Glen Moutrie
  • 295
  • 3
  • 9
  • 1
    There are six billion seconds in that date range. There is a vector creation overflow I assume. That is why it works when you increase the width of the interval. On a 32-bit vector size space, you can have 4 billion maximum. – Gopala Jan 19 '16 at 12:03
  • @mtoto Tried `by = "sec"` and hit the same error. If memory serves this is because `seq.POSIXt()` converts "sec" to 1 internally. – Glen Moutrie Jan 19 '16 at 13:56
  • 1
    @user3949008 I suspect you are correct, especially as `seq.int()` is a primitive function. Thanks! – Glen Moutrie Jan 19 '16 at 13:57

0 Answers0