tidyverse / hms

A simple class for storing time-of-day values
https://hms.tidyverse.org/
Other
138 stars 25 forks source link

Difficult to understand error message for a input of a double with attributes #84

Closed billdenney closed 3 years ago

billdenney commented 4 years ago

This is related to tidyverse/dplyr#5343 in that the issue there is what made me find this issue. Otherwise, the issues are unrelated.

When a double vector with attributes is passed into as_hms() but not hms(), it gives an error that does not indicate the actual problem. I believe that the actual problem is that there are attributes, and the message below does not indicate that. In my real example, I loaded a SAS dataset, and those always come with attributes that I always ignore.

library(hms)
A1 <- structure(1, A="A")
hms(A1)
#> 00:00:01
as_hms(A1)
#> Error: `x` must be a vector with type <double>.
#> Instead, it has type <double>.
A1 <- 1
hms(A1)
#> 00:00:01
as_hms(A1)
#> 00:00:01

Created on 2020-06-19 by the reprex package (v0.3.0)

krlmlr commented 3 years ago

Thanks for reporting this, it looks like a bug:

# options(rlang_backtrace_on_error = "full")
tryCatch(
  hms::as_hms(as.difftime(1:3, units = "secs")),
  error = identity
)
#> <error/vctrs_error_assert_ptype>
#> `x` must be a vector with type <double>.
#> Instead, it has type <integer>.
#> Backtrace:
#>   1. base::tryCatch(...)
#>   5. hms::as_hms(as.difftime(1:3, units = "secs"))
#>   6. vctrs::vec_cast(x, new_hms())
#>   8. hms:::vec_cast.hms.difftime(x = x, to = to, x_arg = x_arg, to_arg = to_arg)
#>   9. hms::new_hms(vec_data(x))
#>  10. vctrs::vec_assert(x, numeric())

Created on 2020-12-22 by the reprex package (v0.3.0)

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.