[CHNOSZ-commits] r727 - in pkg/CHNOSZ: . R inst inst/tinytest
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jun 8 15:58:00 CEST 2022
Author: jedick
Date: 2022-06-08 15:58:00 +0200 (Wed, 08 Jun 2022)
New Revision: 727
Added:
pkg/CHNOSZ/inst/tinytest/test-util.expression.R
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/util.expression.R
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/inst/tinytest/test-util.R
Log:
Make expr.species() recognize non-integer coefficients
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2022-06-04 05:29:26 UTC (rev 726)
+++ pkg/CHNOSZ/DESCRIPTION 2022-06-08 13:58:00 UTC (rev 727)
@@ -1,6 +1,6 @@
-Date: 2022-06-04
+Date: 2022-06-08
Package: CHNOSZ
-Version: 1.9.9-19
+Version: 1.9.9-20
Title: Thermodynamic Calculations and Diagrams for Geochemistry
Authors at R: c(
person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),
Modified: pkg/CHNOSZ/R/util.expression.R
===================================================================
--- pkg/CHNOSZ/R/util.expression.R 2022-06-04 05:29:26 UTC (rev 726)
+++ pkg/CHNOSZ/R/util.expression.R 2022-06-08 13:58:00 UTC (rev 727)
@@ -324,18 +324,19 @@
## like makeup(), but split apart the formula based on
## numbers (subscripts); don't scan for elemental symbols 20171018
# if there are no numbers or charge, return the formula as-is
- if(! (grepl("[0-9]", formula) | grepl("\\+[0-9]?$", formula) | grepl("-[0-9]?$", formula))) return(formula)
+ # Change [0-9]? to [\\.0-9]* (recognize decimal point in numbers, recognize charge longer than one digit) 20220608
+ if(! (grepl("[\\.0-9]", formula) | grepl("\\+[\\.0-9]*$", formula) | grepl("-[\\.0-9]*$", formula))) return(formula)
# first split off charge
# (assume that no subscripts are signed)
Z <- 0
- hascharge <- grepl("\\+[0-9]?$", formula) | grepl("-[0-9]?$", formula)
+ hascharge <- grepl("\\+[\\.0-9]*$", formula) | grepl("-[\\.0-9]*$", formula)
if(hascharge) {
# for charge, we match + or - followed by zero or more numbers at the end of the string
- if(grepl("\\+[0-9]?$", formula)) {
+ if(grepl("\\+[\\.0-9]*$", formula)) {
fsplit <- strsplit(formula, "+", fixed=TRUE)[[1]]
if(is.na(fsplit[2])) Z <- 1 else Z <- as.numeric(fsplit[2])
}
- if(grepl("-[0-9]?$", formula)) {
+ if(grepl("-[\\.0-9]*$", formula)) {
fsplit <- strsplit(formula, "-")[[1]]
# for formula=="H-citrate-2", unsplit H-citrate
if(length(fsplit) > 2) {
@@ -349,10 +350,10 @@
}
# to get strings, replace all numbers with placeholder (#), then split on that symbol
# the outer gsub is to replace multiple #'s with one
- numhash <- gsub("#+", "#", gsub("[0-9]", "#", formula))
+ numhash <- gsub("#+", "#", gsub("[\\.0-9]", "#", formula))
strings <- strsplit(numhash, "#")[[1]]
# to get coefficients, replace all characters (non-numbers) with placeholder, then split
- charhash <- gsub("#+", "#", gsub("[^0-9]", "#", formula))
+ charhash <- gsub("#+", "#", gsub("[^\\.0-9]", "#", formula))
coeffs <- strsplit(charhash, "#")[[1]]
# if the first coefficient is empty, remove it
if(coeffs[1]=="") coeffs <- tail(coeffs, -1) else {
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2022-06-04 05:29:26 UTC (rev 726)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2022-06-08 13:58:00 UTC (rev 727)
@@ -124,6 +124,10 @@
Stacking 2 is bounded by a thick orange line, instead of just the
border shared with bornite.
+ \item Improve handling of non-integer coefficients in
+ \code{expr.species()}. The result for FeS1.33 was previously equivalent
+ to FeS[.33] but is now shown correctly as FeS[1.33].
+
}
}
Modified: pkg/CHNOSZ/inst/tinytest/test-util.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-util.R 2022-06-04 05:29:26 UTC (rev 726)
+++ pkg/CHNOSZ/inst/tinytest/test-util.R 2022-06-08 13:58:00 UTC (rev 727)
@@ -34,9 +34,6 @@
testGHS <- GHS("H2O", G = 0, H = 0)
expect_equal(as.numeric(testGHS[1, 3]), testent[2], info = info)
-info <- "expr.species() produces expected errors"
-expect_error(expr.species(c("H2O", "CO2")), "more than one species", info = info)
-
info <- "[P|T|E].units() do not accept invalid units"
expect_error(P.units("X"), "units of pressure must be either bar or MPa", info = info)
expect_error(T.units("X"), "units of temperature must be either C or K", info = info)
Added: pkg/CHNOSZ/inst/tinytest/test-util.expression.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-util.expression.R (rev 0)
+++ pkg/CHNOSZ/inst/tinytest/test-util.expression.R 2022-06-08 13:58:00 UTC (rev 727)
@@ -0,0 +1,14 @@
+# Load default settings for CHNOSZ
+reset()
+
+info <- "expr.species() produces expected errors"
+expect_error(expr.species(c("H2O", "CO2")), "more than one species", info = info)
+
+# 20220608
+info <- "expr.species() handles non-integer coefficients"
+es <- expr.species("FeS1.33")
+expect_equal(es[[length(es)]], "1.33")
+
+info <- "expr.species() handles non-integer charge"
+es <- expr.species("FeS+1.33")
+expect_equal(es[[length(es)]], "+1.33")
More information about the CHNOSZ-commits
mailing list