[CHNOSZ-commits] r528 - in pkg/CHNOSZ: . R inst man tests/testthat
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jun 16 01:52:14 CEST 2020
Author: jedick
Date: 2020-06-16 01:52:13 +0200 (Tue, 16 Jun 2020)
New Revision: 528
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/add.obigt.R
pkg/CHNOSZ/R/subcrt.R
pkg/CHNOSZ/inst/CHECKLIST
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/info.Rd
pkg/CHNOSZ/man/palply.Rd
pkg/CHNOSZ/man/subcrt.Rd
pkg/CHNOSZ/tests/testthat/test-subcrt.R
Log:
subcrt(): change 'action.unbalanced' argument to 'autobalance'
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2020-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/DESCRIPTION 2020-06-15 23:52:13 UTC (rev 528)
@@ -1,6 +1,6 @@
-Date: 2020-06-10
+Date: 2020-06-16
Package: CHNOSZ
-Version: 1.3.6-5
+Version: 1.3.6-6
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-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/R/add.obigt.R 2020-06-15 23:52:13 UTC (rev 528)
@@ -176,6 +176,6 @@
# give the user a message
message("add.obigt: read ", length(does.exist), " rows; made ",
nexist, " replacements, ", nrow(to2), " additions [energy units: ", Etxt, "]")
- message("add.obigt: use obigt() or reset() to restore default database")
+ #message("add.obigt: use obigt() or reset() to restore default database")
return(invisible(inew))
}
Modified: pkg/CHNOSZ/R/subcrt.R
===================================================================
--- pkg/CHNOSZ/R/subcrt.R 2020-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/R/subcrt.R 2020-06-15 23:52:13 UTC (rev 528)
@@ -14,7 +14,7 @@
subcrt <- function(species, coeff = 1, state = NULL, property = c("logK", "G", "H", "S", "V", "Cp"),
T = seq(273.15, 623.15, 25), P = "Psat", grid = NULL, convert = TRUE, exceed.Ttr = FALSE,
- exceed.rhomin = FALSE, logact = NULL, action.unbalanced = "warn", IS = 0) {
+ exceed.rhomin = FALSE, logact = NULL, autobalance = TRUE, IS = 0) {
# revise the call if the states have
# come as the second argument
@@ -215,12 +215,12 @@
# inform about unbalanced reaction
if(do.reaction) {
- # the mass balance ... is zero for a balanced reaction
+ # the mass balance; should be zero for a balanced reaction
mss <- makeup(ispecies, coeff, sum=TRUE)
# take out very small numbers
mss[abs(mss) < 1e-7] <- 0
# report and try to fix any non-zero mass balance
- if(any(mss!=0) & !is.null(action.unbalanced)) {
+ if(any(mss!=0)) {
# the missing composition: the negative of the mass balance
miss <- -mss
# drop elements that are zero
@@ -230,7 +230,7 @@
message(paste(capture.output(print(miss)), collapse="\n"))
# look for basis species that have our compositoin
tb <- thermo$basis
- if(!is.null(tb)) {
+ if(!is.null(tb) & autobalance) {
if(all(names(miss) %in% colnames(tb)[1:nrow(tb)])) {
# the missing composition as formula
ft <- as.chemical.formula(miss)
@@ -263,12 +263,8 @@
newstate <- c(state, b.state)
return(subcrt(species=newspecies, coeff=newcoeff, state=newstate,
property=property, T=outvert(T, "K"), P=P, grid=grid, convert=convert, logact=logact, exceed.Ttr=FALSE))
- } else if(identical(action.unbalanced,'warn'))
- warnings <- c(warnings, paste('reaction was unbalanced, missing', as.chemical.formula(miss)))
- } else {
- if(identical(action.unbalanced,'warn'))
- warnings <- c(warnings, paste('reaction was unbalanced, missing', as.chemical.formula(miss)))
- }
+ } else warnings <- c(warnings, paste('reaction among', paste(species, collapse = ","), 'was unbalanced, missing', as.chemical.formula(miss)))
+ } else warnings <- c(warnings, paste('reaction among', paste(species, collapse = ","), 'was unbalanced, missing', as.chemical.formula(miss)))
}
}
Modified: pkg/CHNOSZ/inst/CHECKLIST
===================================================================
--- pkg/CHNOSZ/inst/CHECKLIST 2020-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/inst/CHECKLIST 2020-06-15 23:52:13 UTC (rev 528)
@@ -6,6 +6,9 @@
- check output of demo("sources") to make sure all data sources are cited
+- use test_package("CHNOSZ", reporter = "progress") to find warnings
+ from tests that aren't shown in R CMD check
+
- recreate extdata/adds/obigt_check.csv after all data updates:
co <- check.obigt()
write.csv(co, "obigt_check.csv", row.names=FALSE, na="")
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2020-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/inst/NEWS 2020-06-15 23:52:13 UTC (rev 528)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.3.6-4 (2020-06-10)
+CHANGES IN CHNOSZ 1.3.6-4 (2020-06-16)
--------------------------------------
- OBIGT/organic_aq.csv, AkDi.csv, DEW_aq.csv: Remove "methane" as the
@@ -13,6 +13,9 @@
- Add demo/comproportionation.R: Gibbs energy of sulfur
comproportionation, after Amend et al., 2020.
+- subcrt(): change 'action.unbalanced' argument to 'autobalance',
+ which provides the ability to prevent autobalancing.
+
CHANGES IN CHNOSZ 1.3.6 (2020-03-16)
------------------------------------
Modified: pkg/CHNOSZ/man/info.Rd
===================================================================
--- pkg/CHNOSZ/man/info.Rd 2020-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/man/info.Rd 2020-06-15 23:52:13 UTC (rev 528)
@@ -42,7 +42,7 @@
}
-\seealso{ \code{\link{thermo}}, \code{\link{check.obigt}} }
+\seealso{ \code{\link{retrieve}} for searching species by element; \code{\link{check.obigt}} for checking self-consistency of each species. }
\examples{
\dontshow{reset()}
Modified: pkg/CHNOSZ/man/palply.Rd
===================================================================
--- pkg/CHNOSZ/man/palply.Rd 2020-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/man/palply.Rd 2020-06-15 23:52:13 UTC (rev 528)
@@ -12,16 +12,16 @@
}
\arguments{
- \item{...}{equivalent to the same argument in \code{\link[parallel]{parLapply}}}
- \item{varlist}{character, names of variables to export using \code{\link[parallel]{clusterExport}}}
+ \item{...}{equivalent to the same argument in \code{parallel::parLapply}}
+ \item{varlist}{character, names of variables to export using \code{parallel::clusterExport}}
\item{X}{vector, argument for \code{\link{lapply}} or \code{parLapply}}
\item{FUN}{function, argument for \code{lapply} or \code{parLapply}}
}
\details{
-\code{palply} is a wrapper function to run \code{\link[parallel]{parLapply}} if length of \code{X} > \code{\link{thermo}$opt$paramin} and multiple cores are available, otherwise it runs \code{\link{lapply}}.
+\code{palply} is a wrapper function to run \code{parallel::parLapply} (see \code{\link[parallel]{clusterApply}}) if length of \code{X} > \code{\link{thermo}$opt$paramin} and multiple cores are available, otherwise it runs \code{\link{lapply}}.
Note that \code{parLapply} is called with \code{methods} set to FALSE.
-If lots of package startup messages are created when running \code{\link[parallel]{makeCluster}} (which is called by \code{palply}), it can probably be stopped by adding a test for \code{\link{interactive}} sessions around any \code{\link{library}} commands in the \code{\link{Rprofile}}.
+If lots of package startup messages are created when running \code{parallel::makeCluster} (which is called by \code{palply}), it can probably be stopped by adding a test for \code{\link{interactive}} sessions around any \code{\link{library}} commands in the \code{\link{Rprofile}}.
}
\seealso{
Modified: pkg/CHNOSZ/man/subcrt.Rd
===================================================================
--- pkg/CHNOSZ/man/subcrt.Rd 2020-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/man/subcrt.Rd 2020-06-15 23:52:13 UTC (rev 528)
@@ -11,7 +11,7 @@
property = c("logK","G","H","S","V","Cp"),
T = seq(273.15,623.15,25), P = "Psat", grid = NULL,
convert = TRUE, exceed.Ttr = FALSE, exceed.rhomin = FALSE,
- logact = NULL, action.unbalanced = "warn", IS = 0)
+ logact = NULL, autobalance = TRUE, IS = 0)
}
\arguments{
@@ -26,7 +26,7 @@
\item{exceed.rhomin}{logical, return properties of species in the HKF model below 0.35 g cm\S{-3}?}
\item{logact}{numeric, logarithms of activities of species in reaction}
\item{convert}{logical, are input and output units of T and P those of the user (\code{TRUE}) (see \code{\link{T.units}}), or are they Kelvin and bar (\code{FALSE})?}
- \item{action.unbalanced}{character \samp{warn} or NULL, what action to take if unbalanced reaction is provided}
+ \item{autobalance}{logical, attempt to automatically balance reaction with basis species?}
\item{IS}{numeric, ionic strength(s) at which to calculate adjusted molal properties, mol kg\eqn{^{-1}}{^-1}}
}
@@ -61,8 +61,8 @@
A chemical reaction is defined if \code{coeff} is given.
In this mode the standard molal properties of species are summed according to the stoichiometric \code{coeff}icients, where negative values denote reactants.
Reactions that do not conserve elements are permitted; \code{subcrt} prints the missing composition needed to balance the reaction and produces a warning but computes anyway.
-Alternatively, if the \code{\link{basis}} species of a system were previously defined, and if the species being considered are within the compositional range of the basis species, an unbalanced reaction given in the arguments to \code{subcrt} will be balanced automatically, without altering the coefficients on the species identified in the arguments (unless perhaps they correspond to basis species), and without a warning.
-However, if a reaction is unbalanced and \code{action.unbalanced} is set to NULL, no warnings are generated and no attempt is made to balance the reaction.
+Alternatively, if \code{autobalance} is \code{TRUE}, the \code{\link{basis}} species of a system were previously defined, and all elements in the reaction are represented by the basis species, an unbalanced reaction given in the arguments to \code{subcrt} will be balanced automatically.
+The auto balancing doesn't change the reaction coefficients of any species that are do not correspond to basis species.
Minerals with polymorphic transitions (denoted by having states \samp{cr} (lowest T phase), \samp{cr2}, \samp{cr3} etc.) can be defined generically by \samp{cr} in the \code{state} argument with a character value for \code{species}.
\code{subcrt} in this case simultaneously calculates the requested properties of all the phases of each such mineral (phase species) and, using the values of the transition temperatures calculated from those at P = 1 bar given in the thermodynamic database together with functions of the entropies and volumes of transitions (see \code{\link{dPdTtr}}), determines the stable phase of the mineral at any grid point and substitutes the properties of this phase at that point for further calculations.
Modified: pkg/CHNOSZ/tests/testthat/test-subcrt.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-subcrt.R 2020-06-11 00:25:25 UTC (rev 527)
+++ pkg/CHNOSZ/tests/testthat/test-subcrt.R 2020-06-15 23:52:13 UTC (rev 528)
@@ -4,7 +4,7 @@
basis(delete=TRUE)
test_that("unbalanced reactions give a warning or are balanced given sufficient basis species", {
- expect_warning(subcrt(c("glucose", "ethanol"), c(-1, 3)), "reaction was unbalanced, missing H-6O3")
+ expect_warning(subcrt(c("glucose", "ethanol"), c(-1, 3)), "reaction among glucose,ethanol was unbalanced, missing H-6O3")
basis("CHNOS")
s <- subcrt(c("malic acid", "citric acid"), c(-1, 1))
expect_equal(s$reaction$coeff, c(-1, 1, -2, -1, 1.5))
More information about the CHNOSZ-commits
mailing list