Skip to content

Commit

Permalink
force storage mode to double in vctrs cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Enchufa2 committed Sep 15, 2022
1 parent 07b2606 commit 85c9785
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 4 additions & 0 deletions R/tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ vec_cast.units.units = function(x, to, ..., x_arg = "", to_arg = "") {
# conversion might change the type and so must happen first.
out = set_units(x, to_units, mode = "standard")

# Previous conversion may change the storage mode from integer to double
# Let's force the most general one for the destination
storage.mode(to) <- "double"

out_bare = drop_units(out)
to_bare = drop_units(to)
out = vctrs::vec_cast(out_bare, to_bare, ..., x_arg = x_arg, to_arg = to_arg)
Expand Down
6 changes: 0 additions & 6 deletions tests/testthat/test_tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ test_that("units have coercion methods", {
vctrs::vec_cast_common(y, x),
list(set_units(4, "m"), set_units(c(0.01, 0.02, 0.03), "m"))
)

# Casting to integer with fractional cm is lossy
expect_error(
vctrs::vec_cast_common(y, x, .to = set_units(0L, "m")),
class = "vctrs_error_cast_lossy"
)
})

test_that("can combine units vectors", {
Expand Down

0 comments on commit 85c9785

Please sign in to comment.