Skip to content

Commit

Permalink
Merge pull request #52 from meowcat/patch-1
Browse files Browse the repository at this point in the history
Update chemFormula.R, fixing #51
  • Loading branch information
jorainer authored Feb 11, 2022
2 parents e3a622b + 869a4ab commit 4c18c07
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ Authors@R:
person(given = "Sebastian", family = "Gibb",
email = "mail@sebastiangibb.de",
role = "ctb",
comment = c(ORCID = "0000-0001-7406-4443")))
comment = c(ORCID = "0000-0001-7406-4443")),
person(given = "Michael", family = "Stravs",
email = "stravsmi@eawag.ch",
role = "ctb",
comment = c(ORCID = "0000-0002-1426-8572")))
Depends:
R (>= 4.0)
Imports:
Expand Down
2 changes: 1 addition & 1 deletion R/chemFormula.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ standardizeFormula <- function(x) {
#' containsElements("C6H12O6", "NH3")
containsElements <- function(x, y) {
mapply(
FUN = function(xx, yy)all(.sum_elements(c(xx, -yy)) > 0),
FUN = function(xx, yy)all(.sum_elements(c(xx, -yy)) >= 0),
xx = countElements(x), yy = countElements(y),
SIMPLIFY = TRUE, USE.NAMES = FALSE
)
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test_chemFormula.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ test_that("correct formula mathematics", {
## check if formula contains specific sub formulae
expect_identical(containsElements("C6H12O6", "H2O"), TRUE)
expect_identical(containsElements("C6H12O6", "NH3"), FALSE)
expect_identical(containsElements("C10H10F3N3", "F"), TRUE)
expect_identical(containsElements("C10H10F3N3", "F1"), TRUE)
expect_identical(containsElements("C10H10F3N3", "F2"), TRUE)
expect_identical(containsElements("C10H10F3N3", "F3"), TRUE)
expect_identical(containsElements("C10H10F3N3", "F4"), FALSE)

## check formula subtraction (single formulae)
expect_identical(subtractElements("C6H12O6", "H2O"), "C6H10O5")
Expand Down

0 comments on commit 4c18c07

Please sign in to comment.