[CHNOSZ-commits] r321 - in pkg/CHNOSZ: . R inst tests/testthat

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 22 00:27:46 CEST 2018


Author: jedick
Date: 2018-08-22 00:27:45 +0200 (Wed, 22 Aug 2018)
New Revision: 321

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/subcrt.R
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/tests/testthat/test-subcrt.R
Log:
subcrt(): fix incorrect reaction stoichiometry for repeated species


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2018-06-12 06:58:31 UTC (rev 320)
+++ pkg/CHNOSZ/DESCRIPTION	2018-08-21 22:27:45 UTC (rev 321)
@@ -1,6 +1,6 @@
-Date: 2018-06-12
+Date: 2018-08-22
 Package: CHNOSZ
-Version: 1.1.3-28
+Version: 1.1.3-29
 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/subcrt.R
===================================================================
--- pkg/CHNOSZ/R/subcrt.R	2018-06-12 06:58:31 UTC (rev 320)
+++ pkg/CHNOSZ/R/subcrt.R	2018-08-21 22:27:45 UTC (rev 321)
@@ -443,9 +443,7 @@
       out.new[[i]] <- cbind(out.new.entry,data.frame(polymorph=phasestate))
       reaction.new[i,] <- reaction[iphases[phasestate[1]],]
       # mark the minerals with multiple phases
-      rs <- as.character(reaction.new$state)
-      rs[i] <- 'cr*'
-      reaction.new$state <- rs
+      reaction.new$state[i] <- "cr*"
       isaq.new <- c(isaq.new,isaq[iphases[phasestate[1]]])
       iscgl.new <- c(iscgl.new,iscgl[iphases[phasestate[1]]])
       isH2O.new <- c(isH2O.new,isH2O[iphases[phasestate[1]]])
@@ -458,16 +456,19 @@
       # multiple phases aren't involved ... things stay the same
       out.new[[i]] <- out[[iphases]]
       reaction.new[i, ] <- reaction[iphases, ]
-      rs <- as.character(reaction.new$state)
-      rs[i] <- as.character(reaction$state[iphases])
-      reaction.new$state <- rs
+      reaction.new$state[i] <- reaction$state[iphases]
       isaq.new <- c(isaq.new,isaq[iphases])
       iscgl.new <- c(iscgl.new,iscgl[iphases])
       isH2O.new <- c(isH2O.new,isH2O[iphases])
     }
   }
   out <- out.new
+  # remove the rows that were added to keep track of phase transitions
   reaction <- reaction.new[1:length(sinfo),]
+  # the manipulations above should get the correct species indices and state labels,
+  # but if species are (intentionally) repeated, include only the first
+  # (and possibly incorrect) reaction coefficients, so use the originals here 20180822
+  reaction$coeff <- coeff
   isaq <- isaq.new
   iscgl <- iscgl.new
   isH2O <- isH2O.new

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2018-06-12 06:58:31 UTC (rev 320)
+++ pkg/CHNOSZ/inst/NEWS	2018-08-21 22:27:45 UTC (rev 321)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.3-28 (2018-06-12)
+CHANGES IN CHNOSZ 1.1.3-29 (2018-08-22)
 ---------------------------------------
 
 THERMODYNAMIC DATA
@@ -56,11 +56,6 @@
 
 - Add 'srt' argument to diagram() (rotation of line labels).
 
-- Fix a bug where subcrt()$reaction$coeffs was incorrect for reactions
-  involving minerals with phase transitions.
-
-- Fix bug in nonideal() where "Zn" in formula was identified as charge.
-
 - TODO: fix overly long message for info("SiO2").
 
 - In equilibrate(), accept a length > 1 'normalize' argument to
@@ -90,6 +85,17 @@
 - Keywords in basis(): Change 'CHNOPS+' to use O2 instead of e-, and add
   'CHNOPSe' and 'MgCHNOPSe' for sets of basis species that have e-.
 
+BUG FIXES
+
+- Fix a bug where subcrt()$reaction$coeffs was incorrect for reactions
+  involving minerals with phase transitions. Also ensure that the output
+  reaction stoichiometry is correct for duplicated species in reactions.
+  Thanks to Grayson Boyer for the bug report.
+
+- Fix bug in nonideal() where "Zn" in formula was identified as charge.
+  Thanks to Feng Lai for reporting the incorrect behaviour caused by
+  this bug.
+
 CHANGES IN CHNOSZ 1.1.3 (2017-11-13)
 ------------------------------------
 

Modified: pkg/CHNOSZ/tests/testthat/test-subcrt.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-subcrt.R	2018-06-12 06:58:31 UTC (rev 320)
+++ pkg/CHNOSZ/tests/testthat/test-subcrt.R	2018-08-21 22:27:45 UTC (rev 321)
@@ -169,6 +169,21 @@
   expect_equal(as.numeric(a$values[[1]]), c(0, 0))
 })
 
+test_that("reaction coefficients for repeated species are handled correctly", {
+  # these were failing in version 1.1.3
+  s1 <- subcrt(c("quartz", "SiO2"), c(-1, 1))            
+  expect_equal(s1$reaction$coeff, c(-1, 1))
+  s2 <- subcrt(c("pyrrhotite", "pyrrhotite"), c(-1, 1))            
+  expect_equal(s2$reaction$coeff, c(-1, 1))
+  # these were failing in version 1.1.3-28
+  s3 <- subcrt(c("SiO2", "SiO2"), c(-1, 1))
+  expect_equal(s3$reaction$coeff, c(-1, 1))
+  s4 <- subcrt(c("H2O", "H2O", "H2O", "H2O", "H2O"), c(-2, 1, -3, 1, 3))
+  expect_equal(s4$reaction$coeff, c(-2, 1, -3, 1, 3))
+  # the reaction properties here should add up to zero
+  expect_equal(unique(s4$out$logK), 0)
+})
+
 # references
 
 # Amend, J. P. and Shock, E. L. (2001) 



More information about the CHNOSZ-commits mailing list