Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDate Error #1354

Closed
geneorama opened this issue Sep 22, 2015 · 3 comments
Closed

IDate Error #1354

geneorama opened this issue Sep 22, 2015 · 3 comments
Assignees
Milestone

Comments

@geneorama
Copy link

I have a data set with an invalid time stamp, someone put in 14:00 PM.

Normally this converts to NA with IDate, but I found that in some instances it throws an error.

Reproducible example:

library(data.table)

v1 = c("07:36:00", "08:26:00", "08:50:00", "07:05:00", "07:37:00", "08:31:00", 
      "09:41:00", "10:21:00", "11:16:00", "12:05:00", "12:24:00", "12:43:00", 
      "12:52:00", "14:00:00")
v2 = c("AM", "AM", "AM", "AM", "AM", "AM", "AM", "AM", "AM", "PM", "PM", "PM", 
      "PM", "PM")
as.ITime(paste(v1, v2), format="%I:%M:%S %p")
paste(v1, v2)


as.IDate(c("03:00:00 AM", "03:00:00 PM", "15:00:00 AM", "14:00:00 PM"), "%I:%M:%S %p")
as.IDate(c("03:00:00 AM", "03:00:00 PM", "14:00:00 PM"), "%I:%M:%S %p")

"14:00:00 PM" == paste(v1, v2)[14]

Screen grab of what happens when I run the above example:
image

Session Info:

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.9.6

loaded via a namespace (and not attached):
[1] chron_2.3-47

Also..
Strangely if the vectors are inside a data.table, the data.table will let me convert the vectors to an IDate without an error, but then it won't let me use the data.table. The data table now has an error.

v1 and v2 inside a data.table
image

@arunsrinivasan arunsrinivasan added this to the v1.9.8 milestone Sep 22, 2015
@geneorama
Copy link
Author

I think I found the underlying problem, ITime doesn't like NA values
image

@arunsrinivasan
Copy link
Member

Thanks @geneorama, should be fixed now. Please verify.

@geneorama
Copy link
Author

yes, it's fixed.

Thanks. I looked at the code myself and wasn't sure where to start. Looking at your edits gave me some insight into S3 methods and some strategies for debugging.

This has helped me realize that can

  1. clone the project,
  2. source the functions where the error is probably happening, and
  3. debug the a copy of the function in my global environment.

Previously I believed (in error) that data.table was using so much C code that I wouldn't be able to follow the source.

Next time you'll probably get more detail from me in the issue, perhaps with a code sample.

As always, I appreciate your hard work. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants