-
Notifications
You must be signed in to change notification settings - Fork 30
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
unique() drops units #277
Comments
* Implement `unique.units()` * Implement `unique.mixed_units()` * Add tests
I've had a go at implementing After changes: a <- set_units(c(1, 1, 2, 3), kg)
a
#> Units: [kg]
#> [1] 1 1 2 3
unique(a)
#> Units: [kg]
#> [1] 1 2 3
b <- c(set_units(c(1, 1, 2), kg), set_units(c(3, 3, 4), s), allow_mixed = TRUE)
b
#> Mixed units: kg (3), s (3)
#> 1 [kg], 1 [kg], 2 [kg], 3 [s], 3 [s], 4 [s]
unique(b)
#> Mixed units: kg (2), s (2)
#> 1 [kg], 2 [kg], 3 [s], 4 [s] Before I raise a PR I'd like some feedback on something that took me by surprise. If the # The object has two "blocks" of `kg`
z <- c(set_units(c(1, 2), kg), set_units(c(3, 4), s), set_units(c(2, 3), kg), allow_mixed = TRUE)
z
#> Mixed units: kg (4), s (2)
#> 1 [kg], 2 [kg], 3 [s], 4 [s], 2 [kg], 3 [kg] My current implementation gives unique(z)
#> Mixed units: kg (3), s (2)
#> 1 [kg], 2 [kg], 3 [s], 4 [s], 3 [kg] i.e. the result is not ordered by unit (the last # Is this better?
unique(z)
#> Mixed units: kg (3), s (2)
#> 1 [kg], 2 [kg], 3 [kg], 3 [s], 4 [s] |
Thanks, PR very welcome. :)
Your current implementation is correct: order must be preserved. |
* Implement `unique.units()` * Implement `unique.mixed_units()` * Add tests
Implement `unique()` S3 methods (#277)
set_units(5, g) %>% unique
returns 5
would expect 5 g
Thanks :)
The text was updated successfully, but these errors were encountered: