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

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

Closed
billdenney opened this issue Jun 19, 2020 · 2 comments · Fixed by #88
Closed

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

billdenney opened this issue Jun 19, 2020 · 2 comments · Fixed by #88
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@billdenney
Copy link

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
Copy link
Member

krlmlr commented Dec 22, 2020

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)

@krlmlr krlmlr added the bug an unexpected problem or unintended behavior label Dec 22, 2020
@krlmlr krlmlr added this to the 1.0.0 milestone Jan 12, 2021
krlmlr added a commit that referenced this issue Jan 12, 2021
- `as_hms()` and `vec_cast()` now correctly treat objects of class `"difftime"` with `integer` mode (#84).
@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants