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

zero-length ITime doesn't like substr #2852

Closed
franknarf1 opened this issue May 8, 2018 · 3 comments
Closed

zero-length ITime doesn't like substr #2852

franknarf1 opened this issue May 8, 2018 · 3 comments

Comments

@franknarf1
Copy link
Contributor

I'm formatting an ITime for printing out to CSV like HH:MM (truncating/throwing away seconds, mentioned in #1979). Since that's not a built-in option for fwrite, I set up the workaround of using substr, but it fails if my table has zero rows:

library(data.table)
x = as.ITime("01:00")[0L]
invisible(substr(x, 1, 5))
# Error in substring(paste("0", hh, sep = ""), nchar(paste(hh))) : 
#   invalid substring arguments

I'm not sure if that can be fixed or is worth fixing, but figured I'd post just in case. I wrapped in invisible since apparently last time (#2032) it was related to printing to console.

I'll just switch to sprintf("%02d:%02d", hour(x), minute(x)) for now.

@MichaelChirico
Copy link
Member

format(x, '%H:%M')?

@MichaelChirico
Copy link
Member

Anyway your code doesn't error for me?

@franknarf1
Copy link
Contributor Author

Thanks for checking, Michael. Going to close for now since I cannot test on devel from here and seems it's no-repro.

(I still see it here on 1.10.4-3 on r 3.3.3, where the format(x, '%H:%M') way gives the same error for whatever reason.)

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

2 participants