forked from PecanProject/pecan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PecanProject#2989 from nanu1605/replace_udunits2
Replace udunits2 with units
- Loading branch information
Showing
109 changed files
with
362 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ Imports: | |
rlang, | ||
tibble, | ||
tidyr, | ||
udunits2, | ||
units | ||
Suggests: | ||
bit64, | ||
data.table, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ Imports: | |
RCurl, | ||
rlang, | ||
stringi, | ||
udunits2 (>= 0.11), | ||
units, | ||
XML | ||
Suggests: | ||
coda (>= 0.18), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
##' Convert units | ||
##' | ||
##' Unit conversion to replace the now-unmaintained `udunits2::ud.convert` | ||
##' @author Chris Black | ||
##' | ||
##' @param x numeric vector | ||
##' @param u1 string parseable as the units in which `x` is provided | ||
##' @param u2 string parseable as the units to convert to | ||
##' | ||
##' @return numeric vector with values converted to units in `u2` | ||
##' @export | ||
ud_convert <- function(x, u1, u2) { | ||
stopifnot(units::ud_are_convertible(u1, u2)) | ||
x1 <- units::set_units(x, value = u1, mode = "standard") | ||
x2 <- units::set_units(x1, value = u2, mode = "standard") | ||
|
||
units::drop_units(x2) | ||
} # ud_convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
test_that("unit conversions", { | ||
expect_equal(ud_convert(4, "in", "cm"), 10.16) | ||
expect_equal(ud_convert(23, "degC", "K"), 296.15) | ||
expect_equal(ud_convert(6, "days", "seconds"), 518400) | ||
expect_equal(ud_convert(32, "hour", "seconds"), 115200) | ||
expect_equal(ud_convert(15, "days", "hour"), 360) | ||
expect_equal(ud_convert(-7, "ppm", "mol/mol"), -7e-06) | ||
}) | ||
|
||
test_that("unit conversion invariants", { | ||
expect_equal(ud_convert(1, "g", "g"), 1) | ||
expect_equal(ud_convert(0, "g", "kg"), 0) | ||
expect_equal(ud_convert(Inf, "g", "kg"), Inf) | ||
}) | ||
|
||
test_that("incompatible units", { | ||
expect_error(ud_convert(1, "miles", "grams")) | ||
expect_error(ud_convert(1, "radians", "degC")) | ||
expect_error(ud_convert(1, "in", "grams")) | ||
}) | ||
|
||
test_that("output is type numeric and not class \"units\"", { | ||
x <- ud_convert(23, "degC", "K") | ||
testthat::expect_failure(expect_s3_class(x, "units")) | ||
testthat::expect_type(x, "double") | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.