[CHNOSZ-commits] r668 - in pkg/CHNOSZ: . R demo inst man tests/testthat

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 7 12:41:19 CEST 2021


Author: jedick
Date: 2021-04-07 12:41:18 +0200 (Wed, 07 Apr 2021)
New Revision: 668

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/mosaic.R
   pkg/CHNOSZ/R/solubility.R
   pkg/CHNOSZ/demo/mosaic.R
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/inst/TODO
   pkg/CHNOSZ/man/mosaic.Rd
   pkg/CHNOSZ/tests/testthat/test-mosaic.R
Log:
Remove old 'bases2' argument from mosaic()


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2021-04-07 10:20:48 UTC (rev 667)
+++ pkg/CHNOSZ/DESCRIPTION	2021-04-07 10:41:18 UTC (rev 668)
@@ -1,6 +1,6 @@
 Date: 2021-04-07
 Package: CHNOSZ
-Version: 1.4.0-37
+Version: 1.4.0-38
 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/mosaic.R
===================================================================
--- pkg/CHNOSZ/R/mosaic.R	2021-04-07 10:20:48 UTC (rev 667)
+++ pkg/CHNOSZ/R/mosaic.R	2021-04-07 10:41:18 UTC (rev 668)
@@ -11,7 +11,7 @@
 #source("util.args.R")
 
 # function to calculate affinities with mosaic of basis species
-mosaic <- function(bases, bases2 = NULL, blend = TRUE, stable = list(), ...) {
+mosaic <- function(bases, blend = TRUE, stable = list(), ...) {
 
   # argument recall 20190120
   # if the first argument is the result from a previous mosaic() calculation,
@@ -33,22 +33,13 @@
 
   # backward compatibility 20190131:
   # bases can be a vector instead of a list
-  # bases2 can be present
   if(!is.list(bases)) {
     bases <- list(bases)
-    hasbases2 <- FALSE
-    if(!is.null(bases2)) {
-      bases <- c(bases, list(bases2))
-      hasbases2 <- TRUE
-    }
     otherargs <- list(...)
     allargs <- c(list(bases = bases, blend = blend, stable = stable), otherargs)
     out <- do.call(mosaic, allargs)
-    # replace A.bases (affinity calculations for all groups of basis species) with backwards-compatbile A.bases and A.bases2
-    if(hasbases2) A.bases2 <- out$A.bases[[2]]
-    A.bases <- out$A.bases[[1]]
-    out$A.bases <- A.bases
-    if(hasbases2) out <- c(out, list(A.bases2 = A.bases2))
+    # replace A.bases (affinity calculations for all groups of basis species) with backwards-compatbile A.bases
+    out$A.bases <- out$A.bases[[1]]
     return(out)
   }
 

Modified: pkg/CHNOSZ/R/solubility.R
===================================================================
--- pkg/CHNOSZ/R/solubility.R	2021-04-07 10:20:48 UTC (rev 667)
+++ pkg/CHNOSZ/R/solubility.R	2021-04-07 10:41:18 UTC (rev 668)
@@ -28,7 +28,7 @@
     is.mosaic <- TRUE
     # For getting 'sout' from affinity(), drop arguments specific for mosaic()
     affargs <- ddd[-1]
-    affargs <- affargs[!names(affargs) %in% c("bases", "bases2", "stable", "blend")]
+    affargs <- affargs[!names(affargs) %in% c("bases", "stable", "blend")]
   }
 
   # Save current thermodynamic system settings

Modified: pkg/CHNOSZ/demo/mosaic.R
===================================================================
--- pkg/CHNOSZ/demo/mosaic.R	2021-04-07 10:20:48 UTC (rev 667)
+++ pkg/CHNOSZ/demo/mosaic.R	2021-04-07 10:41:18 UTC (rev 668)
@@ -37,17 +37,19 @@
 # Use two sets of changing basis species:
 #   speciate SO4-2, HSO4-, HS-, H2S as a function of Eh and pH
 #   speciate CO3-2, HCO3-, CO2 as a function of pH
-bases <- c("SO4-2", "HSO4-", "HS-", "H2S")
-bases2 <- c("CO3-2", "HCO3-", "CO2")
+bases <- list(
+  c("SO4-2", "HSO4-", "HS-", "H2S"),
+  c("CO3-2", "HCO3-", "CO2")
+)
 
 # Make a diagram with dotted lines and aqueous species labels for log(activity of aqueous Fe species) = -4
-m4 <- mosaic(bases, bases2, pH = pH, Eh = Eh, T = T, P = P)
+m4 <- mosaic(bases, pH = pH, Eh = Eh, T = T, P = P)
 names.aq <- species()$name; names.aq[4:8] <- ""
 diagram(m4$A.species, lty = 3, names = names.aq, col.names = 4)
 
 # Overlay solid lines and mineral labels for log(activity of aqueous Fe species) = -6
 species(c("Fe+2", "Fe+3", "HFeO2-"), -6)
-m6 <- mosaic(bases, bases2, pH = pH, Eh = Eh, T = T, P = P)
+m6 <- mosaic(bases, pH = pH, Eh = Eh, T = T, P = P)
 names <- species()$name; names[1:3] <- ""
 # Adjust labels
 srt <- dy <- numeric(length(names))
@@ -60,8 +62,8 @@
 diagram(m4$A.species, lty = 3, names = names.aq, col.names = 4, add = TRUE, fill = NA)
 
 # Show the predominance fields for the sulfur and carbonate basis species
-dS <- diagram(m4$A.bases, italic = TRUE, plot.it = FALSE)
-dC <- diagram(m4$A.bases2, italic = TRUE, plot.it = FALSE)
+dS <- diagram(m4$A.bases[[1]], italic = TRUE, plot.it = FALSE)
+dC <- diagram(m4$A.bases[[2]], italic = TRUE, plot.it = FALSE)
 dSC <- mash(dS, dC)
 diagram(dSC, lty = 2, col = 8, col.names = 8, add = TRUE, srt = 90)
 

Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd	2021-04-07 10:20:48 UTC (rev 667)
+++ pkg/CHNOSZ/inst/NEWS.Rd	2021-04-07 10:41:18 UTC (rev 668)
@@ -10,7 +10,7 @@
 \newcommand{\s}{\ifelse{latex}{\eqn{_{#1}}}{\ifelse{html}{\out{<sub>#1</sub>}}{#1}}}
 \newcommand{\S}{\ifelse{latex}{\eqn{^{#1}}}{\ifelse{html}{\out{<sup>#1</sup>}}{^#1}}}
 
-\section{Changes in CHNOSZ version 1.4.0-37 (2021-04-07)}{
+\section{Changes in CHNOSZ version 1.4.0-38 (2021-04-07)}{
 
   \subsection{NEW FEATURES}{
     \itemize{
@@ -105,6 +105,9 @@
         = "AkDi"} for any aqueous species, instead of setting the charge
       (\code{z}) to NA. This simplifies the more common use case of adding a
       custom aqueous species to OBIGT with mostly NA parameters.
+
+      \item Remove \samp{bases2} argument from \code{mosaic()} (old backward
+      compatibility feature).
       
     }
   }

Modified: pkg/CHNOSZ/inst/TODO
===================================================================
--- pkg/CHNOSZ/inst/TODO	2021-04-07 10:20:48 UTC (rev 667)
+++ pkg/CHNOSZ/inst/TODO	2021-04-07 10:41:18 UTC (rev 668)
@@ -40,7 +40,3 @@
 
 - Add demo for effective equilibrium constant for diglycine on T-pH plot at
   high pressure (DEW model; Robinson et al., 2021)
-
-[20210306]
-
-- Remove 'bases2' argument from mosaic() (old backward compatibility)

Modified: pkg/CHNOSZ/man/mosaic.Rd
===================================================================
--- pkg/CHNOSZ/man/mosaic.Rd	2021-04-07 10:20:48 UTC (rev 667)
+++ pkg/CHNOSZ/man/mosaic.Rd	2021-04-07 10:41:18 UTC (rev 668)
@@ -7,12 +7,11 @@
 }
 
 \usage{
-  mosaic(bases, bases2 = NULL, blend = TRUE, stable = list(), ...)
+  mosaic(bases, blend = TRUE, stable = list(), ...)
 }
 
 \arguments{
-  \item{bases}{character, basis species to be changed in the calculation, or list, containing vectors for each group of changing basis species}
-  \item{bases2}{character, second set of changing basis species}
+  \item{bases}{character, basis species to be changed in the calculation, or list, each element of which defines an independent group of changing basis species}
   \item{blend}{logical, use relative abundances of basis species?}
   \item{stable}{list, previously determined stable species}
   \item{...}{additional arguments to be passed to \code{\link{affinity}}}
@@ -25,13 +24,14 @@
 For example, the speciation of sulfur (\samp{SO4-2}, \samp{HSO4-}, \samp{HS-} and \samp{H2S}) as a function of Eh and pH affects the formation affinities, and therefore relative stabilities of iron oxide and sulfide minerals.
 Chemical activity diagrams constructed by assembling sub-diagrams corresponding to the predominant (i.e. most stable) basis species can described as \dQuote{mosaic diagrams}.
 
-The function calculates the affinities using all combination of basis species given as vector arguments to \code{bases} and \code{bases2}.
+The function calculates the affinities using all combination of basis species given as a vector argument to \code{bases}.
+Or, a list can be provided contain any number of vectors that specify different groups of basis species.
+All combinations of basis species in these groups are used for the calculations.
+
 The first species listed in each group should be in the current basis definition, and all the basis species in each group should be related to the first basis species there (i.e. all share the same element).
-A second, independent set of basis species can be provided in \code{bases2} (for example \samp{CO3-2}, \samp{HCO3-}, \samp{CO2}, if the first set of basis species are the sulfur-bearing ones listed above).
 The arguments in \code{...} are passed to \code{affinity} to specify the variable conditions, such as temperature, pressure, and activities of other basis species.
 
 \code{blend} can be a single logical value or multiple values, in order to control the calculations for individual groups of basis species.
-
 If \code{blend} is TRUE (the default), the relative abundances of the basis species in each group are calculated using \code{\link{equilibrate}}, with the total activity taken from the corresponding basis species in the incoming \code{\link{basis}} definition.
 Then, the function calculates overall affinities of the formation reactions of each species by combining reactions written using individual basis species in proportion to the relative abundances of the basis species.
 
@@ -44,23 +44,17 @@
 This is useful for diagrams for minerals with multiple metallic elements.
 Note that a value in any position of the \code{stable} list forces \code{blend = FALSE} for the corresponding group of basis species, so there is no need to explicity change the \code{blend} argument.
 
-A more flexible method of specifying multiple sets of basis species is now available.
-Instead of using \code{bases} and \code{bases2}, supply a list for just the \code{bases} argument.
-The list should contain any number of vectors specifying the groups of basis species.
-All combinations of basis species in these groups are used for the calculations.
-This overcomes the prior limitation of only having two changing groups of basis species.
-
 }
 
 \value{
 A list containing \code{A.species} (affinities of formation of the species with changing basis species) and \code{A.bases} (affinities of formation of the basis species in terms of the first basis species), each having same structure as the list returned by \code{\link{affinity}}.
+If \code{bases} is a list, \code{A.bases} is also a list, each element of which corresponds to a group of basis species in \code{bases}.
 If \code{blend} is TRUE, the output also contains \code{E.bases} (the output of \code{\link{equilibrate}} for each group of basis species)
-If \code{bases2} is provided, the list also contains \code{A.bases2} (affinities of formation of the second group of basis species).
 }
 
 \seealso{
-\code{demo("mosaic")}, extending the example below by addition of carbonate species in \code{bases2}, and using thermodynamic data from Garrels and Christ, 1965.
-The help page of \code{\link{solubility}} has an example combining \code{mosaic} with solubility calculations.
+\code{demo("mosaic")}, which extends the example below with carbonate species in order to plot a siderite field.
+To calculate mineral solubilities with mosaic calculations that account for ligand speciation, use \code{bases} as the first argument to \code{\link{solubility}}.
 }
 
 \examples{

Modified: pkg/CHNOSZ/tests/testthat/test-mosaic.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-mosaic.R	2021-04-07 10:20:48 UTC (rev 667)
+++ pkg/CHNOSZ/tests/testthat/test-mosaic.R	2021-04-07 10:41:18 UTC (rev 668)
@@ -157,6 +157,4 @@
   expect_equivalent(Adiff, rep(0, length(Adiff)))
 })
 
-# TODO: test that basis specifications can be exchanged between bases and bases2 without altering output
-
 }



More information about the CHNOSZ-commits mailing list