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

Replace udunits2::ud.is.parseable with PEcAn.utils::unit_is_parseable #3002

Merged
merged 9 commits into from Aug 5, 2022
1 change: 1 addition & 0 deletions CITATION.cff
Expand Up @@ -59,6 +59,7 @@ authors:
orcid: 'https://orcid.org/0000-0002-5845-5628'
- given-names: Ayush Pradad
- given-names: Shashank Singh
- given-names: Tanishq Jain
- affiliation: Boston University
given-names: Alexis Helgeson
- affiliation: Pacific Northwest National Laboratory / University of Maryland
Expand Down
2 changes: 2 additions & 0 deletions base/utils/DESCRIPTION
Expand Up @@ -21,6 +21,8 @@ Authors@R: c(person("Mike", "Dietze", role = c("aut"),
email = "shashanksingh819@gmail.com"),
person("Chris", "Black", role = c("aut"),
email = "chris@ckblack.org"),
person("Tanishq", "Jain", role = c("aut"),
email = "tanishqjain010@gmail.com"),
person("University of Illinois, NCSA", role = c("cph")))
Description: The Predictive Ecosystem Carbon Analyzer
(PEcAn) is a scientific workflow management tool that
Expand Down
1 change: 1 addition & 0 deletions base/utils/NAMESPACE
Expand Up @@ -55,6 +55,7 @@ export(trait.lookup)
export(transformstats)
export(tryl)
export(ud_convert)
export(unit_is_parseable)
export(units_are_equivalent)
export(vecpaste)
export(zero.truncate)
Expand Down
17 changes: 17 additions & 0 deletions base/utils/R/unit_is_parseable.R
@@ -0,0 +1,17 @@
##' Check whether a unit string is parseable
nanu1605 marked this conversation as resolved.
Show resolved Hide resolved
##'
##' Function will replace the now-unmaintained `udunits2::ud.is.parseable`
##' @author Tanishq Jain
##'
##' @param u1 A character string representing a type of units
##'
##' @return TRUE if the units is parseable, FALSE otherwise.
##' @export
unit_is_parseable <- function(u1){
tryCatch({
if(units::as_units(u1))
nanu1605 marked this conversation as resolved.
Show resolved Hide resolved
return(TRUE)
},
error = function(e) FALSE
)
} # unit_is_parseable
nanu1605 marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions base/utils/man/unit_is_parseable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions base/utils/tests/testthat/test-unit_is_parseable.R
@@ -0,0 +1,20 @@
test_that("parseable unit", {
expect_true(unit_is_parseable("miles"))
expect_true(unit_is_parseable(" K "))
expect_true(unit_is_parseable("10cm"))
expect_true(unit_is_parseable("m/s"))
expect_true(unit_is_parseable("kg"))
})

test_that("Non-paresable unit", {
expect_false(unit_is_parseable("fake"))
expect_false(unit_is_parseable("gk"))
expect_false(unit_is_parseable(NULL))
expect_false(unit_is_parseable("Not parseable"))
expect_false(unit_is_parseable("Loading"))
nanu1605 marked this conversation as resolved.
Show resolved Hide resolved
})

# This differ from `udunits2::ud.is.parseable`
#test_that("incompatiable unit to parse", {
# expect_error(unit_is_parseable(""))
#})
nanu1605 marked this conversation as resolved.
Show resolved Hide resolved