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

as.ITime(character(0)) fails #2032

Closed
arunsrinivasan opened this issue Feb 17, 2017 · 1 comment
Closed

as.ITime(character(0)) fails #2032

arunsrinivasan opened this issue Feb 17, 2017 · 1 comment

Comments

@arunsrinivasan
Copy link
Member

arunsrinivasan commented Feb 17, 2017

require(data.table)
as.ITime(character(0))
# Error in substring(paste("0", hh, sep = ""), nchar(paste(hh))) : 
#   invalid substring arguments

The issue is very likely in format.ITime. I think the behaviour should be similar to as.Date(), as.IDate() and as.POSIXct().

@MichaelChirico
Copy link
Member

MichaelChirico commented Feb 17, 2017

x = as.ITime(character(0))

is OK.

so it's print(x) causing the issue (more specifically, format.ITime, like you suggested).

We've got

#stylized from format.ITime
x = structure(integer(0), class = "ITime")
hh = x %/% 3600L
ss = paste("0", hh, sep = "")
nn = nchar(paste(hh))
#Error caused by:
substring(ss, nn)

We can just replace the substring bit with a sprintf call, I think... PRing now

@mattdowle mattdowle added this to the v1.10.6 milestone May 11, 2017
mattdowle added a commit that referenced this issue May 11, 2017
Closes #2032 -- error in format.ITime edge case (0-length input)
mattdowle added a commit that referenced this issue May 20, 2017
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