[CHNOSZ-commits] r551 - in pkg/CHNOSZ: . R inst tests/testthat
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jul 7 04:09:28 CEST 2020
Author: jedick
Date: 2020-07-07 04:09:27 +0200 (Tue, 07 Jul 2020)
New Revision: 551
Added:
pkg/CHNOSZ/tests/testthat/test-mod.OBIGT.R
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/add.OBIGT.R
pkg/CHNOSZ/R/info.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/tests/testthat/test-thermo.R
Log:
Revise NEWS and add warning for aqueous methane (now CH4)
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2020-07-06 15:49:37 UTC (rev 550)
+++ pkg/CHNOSZ/DESCRIPTION 2020-07-07 02:09:27 UTC (rev 551)
@@ -1,6 +1,6 @@
-Date: 2020-07-06
+Date: 2020-07-07
Package: CHNOSZ
-Version: 1.3.6-24
+Version: 1.3.6-25
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/add.OBIGT.R
===================================================================
--- pkg/CHNOSZ/R/add.OBIGT.R 2020-07-06 15:49:37 UTC (rev 550)
+++ pkg/CHNOSZ/R/add.OBIGT.R 2020-07-07 02:09:27 UTC (rev 551)
@@ -31,6 +31,7 @@
# if the first argument is numeric, it's the species index
if(is.numeric(args[[1]][1])) {
ispecies <- args[[1]]
+ args <- args[-1]
} else {
# if the name of the first argument is missing, assume it's the species name
if(names(args)[1]=="") names(args)[1] <- "name"
Modified: pkg/CHNOSZ/R/info.R
===================================================================
--- pkg/CHNOSZ/R/info.R 2020-07-06 15:49:37 UTC (rev 550)
+++ pkg/CHNOSZ/R/info.R 2020-07-07 02:09:27 UTC (rev 551)
@@ -80,6 +80,7 @@
# returns the rownumbers of thermo()$OBIGT having an exact match of 'species' to
# thermo()$OBIGT$[species|abbrv|formula] or NA otherwise
# a match to thermo()$OBIGT$state is also required if 'state' is not NULL
+
# (first occurence of a match to species is returned otherwise)
thermo <- get("thermo", CHNOSZ)
# find matches for species name, abbreviation or formula
@@ -123,6 +124,10 @@
a.s.text <- paste("'", available.states, "'", sep="", collapse=" ")
message("info.character: requested state '", state, "' for ", species,
" but only ", a.s.text, " ", a.s.verb, " available")
+ # warn about looking for aqueous methane (changed to CH4) 20200707
+ if(identical(species, "methane") & identical(state, "aq")) {
+ warning("'methane' is not an aqueous species; use 'CH4' instead\nTo revert to the old behavior, run mod.OBIGT(info('CH4'), name = 'methane')")
+ }
return(NA)
}
matches.species <- matches.state
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2020-07-06 15:49:37 UTC (rev 550)
+++ pkg/CHNOSZ/inst/NEWS 2020-07-07 02:09:27 UTC (rev 551)
@@ -1,22 +1,27 @@
-CHANGES IN CHNOSZ 1.3.6-23 (2020-07-06)
+CHANGES IN CHNOSZ 1.3.6-24 (2020-07-07)
---------------------------------------
MAJOR CHANGES
-- File, function, and object names consistently use the uppercase
- abbreviation OBIGT. In particular, the active database now resides at
- thermo()$OBIGT, and functions add.OBIGT() and mod.OBIGT() replace the
- previous add.obigt() and mod.obigt().
+- The naming convention for methane has changed. The name "methane"
+ now applies exclusively to the gas; "CH4", as before, represents the
+ aqueous species. This behavior is consistent with inorganic gases
+ but differs from most organic substances, where the English names
+ refer to the aqueous species. This change was made because in the past
+ there was no way to use info() or subcrt() with a single character
+ argument to identify gaseous methane, which is common in geochemistry.
+ (Note that info("CH4", "gas") can still be used.) A hack to revert to
+ the old behavior is mod.OBIGT(info("CH4"), name = "methane").
+- The all-uppercase abbreviation OBIGT is now used for all file,
+ function, and object names. In particular, the active database now
+ sits at thermo()$OBIGT, and functions add.OBIGT() and mod.OBIGT()
+ replace the previous add.obigt() and mod.obigt().
+
CHANGES TO OBIGT DATABASE
- Update species parameters for the 2019 Deep Earth Water (DEW) model.
-- organic_aq.csv, AkDi.csv, DEW.csv: Remove "methane" as the name of
- CH4(aq). This means that info("methane") now refers to the gas rather
- than the aqueous species. This is consistent with the behavior for the
- names of inorganic species, e.g. carbon dioxide and oxygen.
-
- OBIGT/SUPCRT92.csv: Change lowercase to uppercase "A" (Angstrom) in
names of minerals with suffixes indicating interlayer spacing
(amesite, clinochlore, cronstedtite, daphnite).
@@ -87,6 +92,10 @@
- TODO: demo/saturation.R: put Al+3 first in basis definition (it's
confusing to have H2O first when the reacitons are balanced on Al)
+- TODO: diagram(): make error or warning for NA values of affinity
+
+- TODO: use markup in NEWS
+
CHANGES IN CHNOSZ 1.3.6 (2020-03-16)
------------------------------------
Added: pkg/CHNOSZ/tests/testthat/test-mod.OBIGT.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-mod.OBIGT.R (rev 0)
+++ pkg/CHNOSZ/tests/testthat/test-mod.OBIGT.R 2020-07-07 02:09:27 UTC (rev 551)
@@ -0,0 +1,34 @@
+context("mod.OBIGT")
+
+# clear out any previous basis definition or database alterations
+suppressMessages(reset())
+
+test_that("minimal usage of mod.OBIGT() creates usable data entries", {
+ # we need at least a name and some property
+ expect_error(mod.OBIGT("test"), "species name and a property")
+ # a valid formula is needed
+ expect_warning(expect_error(mod.OBIGT("test", date=today()), "is not a simple chemical formula"),
+ "please supply a valid chemical formula")
+ # the default state is aq
+ expect_message(itest <- mod.OBIGT("test", formula="Z0", date=today()), "added test\\(aq\\)")
+ # set the charge so following test use hkf() rather than AkDi()
+ mod.OBIGT("test", z = 0)
+ # we should get NA values of G for a species with NA properties
+ expect_true(all(is.na(subcrt(itest)$out[[1]]$G)))
+ # a single value of G comes through to subcrt
+ mod.OBIGT("test", G=100)
+ expect_equal(subcrt("test", T=25, P=1)$out[[1]]$G, 100)
+ # values for Cp and c1 integrate to the same values of G
+ G.Cp <- subcrt(mod.OBIGT(list(name="test", S=0, Cp=100)))$out[[1]]$G
+ G.c1 <- subcrt(mod.OBIGT(list(name="test", S=0, c1=100)))$out[[1]]$G
+ expect_equal(G.Cp, G.c1)
+})
+
+test_that("mod.OBIGT() works with numeric argument (species index)", {
+ # test added 20200707
+ i1 <- info("CH4")
+ # previously this failed with an error
+ i2 <- mod.OBIGT(i1, name = "methane")
+ expect_identical(i1, i2)
+ expect_identical(info(i2)$name, "methane")
+})
Modified: pkg/CHNOSZ/tests/testthat/test-thermo.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-thermo.R 2020-07-06 15:49:37 UTC (rev 550)
+++ pkg/CHNOSZ/tests/testthat/test-thermo.R 2020-07-07 02:09:27 UTC (rev 551)
@@ -21,24 +21,3 @@
# be nice and restore the database
suppressMessages(reset())
})
-
-test_that("minimal usage of mod.OBIGT() creates usable data entries", {
- # we need at least a name and some property
- expect_error(mod.OBIGT("test"), "species name and a property")
- # a valid formula is needed
- expect_warning(expect_error(mod.OBIGT("test", date=today()), "is not a simple chemical formula"),
- "please supply a valid chemical formula")
- # the default state is aq
- expect_message(itest <- mod.OBIGT("test", formula="Z0", date=today()), "added test\\(aq\\)")
- # set the charge so following test use hkf() rather than AkDi()
- mod.OBIGT("test", z = 0)
- # we should get NA values of G for a species with NA properties
- expect_true(all(is.na(subcrt(itest)$out[[1]]$G)))
- # a single value of G comes through to subcrt
- mod.OBIGT("test", G=100)
- expect_equal(subcrt("test", T=25, P=1)$out[[1]]$G, 100)
- # values for Cp and c1 integrate to the same values of G
- G.Cp <- subcrt(mod.OBIGT(list(name="test", S=0, Cp=100)))$out[[1]]$G
- G.c1 <- subcrt(mod.OBIGT(list(name="test", S=0, c1=100)))$out[[1]]$G
- expect_equal(G.Cp, G.c1)
-})
More information about the CHNOSZ-commits
mailing list