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

Confusing error message if type differs between units objects #4138

Closed
kendonB opened this issue Jan 30, 2019 · 6 comments
Closed

Confusing error message if type differs between units objects #4138

kendonB opened this issue Jan 30, 2019 · 6 comments
Milestone

Comments

@kendonB
Copy link

kendonB commented Jan 30, 2019

See below:

library(dplyr)
library(units)
#> udunits system database from C:/R/Library/3.5/units/share/udunits
if_else(TRUE, c(1) %>% set_units("m"), c(1L) %>% set_units("m"))
#> Error: `false` must be a `units` object, not a `units` object

Created on 2019-01-30 by the reprex package (v0.2.1.9000)

@kendonB kendonB changed the title Confusing error message is type differs between units objects Confusing error message if type differs between units objects Jan 30, 2019
@romainfrancois
Copy link
Member

🤔 so this happens in check_type():

check_type <- function(x, template, header) {
  if (identical(typeof(x), typeof(template))) {
    return()
  }

  glubort(header, "must be {friendly_type_of(template)}, not {friendly_type_of(x)}")
}

where it checks the underlying type but then errors based on a higher level class. It might be something vctrs could help with, perhaps with implementations of vctrs::vec_ptype_abbr() and/or vctrs::vec_ptype_full() for units objects.

@romainfrancois romainfrancois added this to the 0.9.0 milestone Jan 30, 2019
@hadley
Copy link
Member

hadley commented Feb 1, 2019

This will be fixed through a complete overhaul of ifelse

@kendonB
Copy link
Author

kendonB commented Feb 1, 2019

This is also a problem with case_when, fyi.

@hadley
Copy link
Member

hadley commented Feb 1, 2019

Yeah, it's a problem with a bunch of functions. We know about it and we have a plan to fix it.

@hadley
Copy link
Member

hadley commented May 27, 2019

Duplicate of #2432

@hadley hadley marked this as a duplicate of #2432 May 27, 2019
@hadley hadley closed this as completed May 27, 2019
@lock
Copy link

lock bot commented Nov 23, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Nov 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants