Skip to content

Commit

Permalink
force storage mode to double at entry point, fixes #324
Browse files Browse the repository at this point in the history
  • Loading branch information
Enchufa2 committed Apr 23, 2023
1 parent f7088ae commit f8f8c7e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 2 additions & 0 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
if(!length(value))
return(x)

storage.mode(x) <- "double" # issues/324

if(!inherits(value, "units") && !inherits(value, "symbolic_units"))
value <- as_units(value)

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
2 changes: 1 addition & 1 deletion tests/testthat/test_unit_creation.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ test_that("various forms of unit creation and destruction work", {
expect_error(drop_units(x))


ox <- x <- data.frame(x=1:4, y=1:4)
ox <- x <- data.frame(x=ox, y=ox)

units(x[[1]]) <- "m/s"
expect_s3_class(x[[1]], "units")
Expand Down

0 comments on commit f8f8c7e

Please sign in to comment.