[CHNOSZ-commits] r128 - in pkg/CHNOSZ: . R inst man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 4 15:11:59 CET 2017


Author: jedick
Date: 2017-02-04 15:11:59 +0100 (Sat, 04 Feb 2017)
New Revision: 128

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/diagram.Rd
   pkg/CHNOSZ/vignettes/anintro.Rmd
Log:
diagram() applies formatting to chemical formulas


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2017-02-04 12:55:30 UTC (rev 127)
+++ pkg/CHNOSZ/DESCRIPTION	2017-02-04 14:11:59 UTC (rev 128)
@@ -1,6 +1,6 @@
 Date: 2017-02-04
 Package: CHNOSZ
-Version: 1.0.8-17
+Version: 1.0.8-18
 Title: Chemical Thermodynamics and Activity Diagrams
 Author: Jeffrey Dick
 Maintainer: Jeffrey Dick <j3ffdick at gmail.com>

Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R	2017-02-04 12:55:30 UTC (rev 127)
+++ pkg/CHNOSZ/R/diagram.R	2017-02-04 14:11:59 UTC (rev 128)
@@ -22,7 +22,7 @@
   # colors
   bg=par("bg"), col=par("col"), col.names=par("col"), fill=NULL, 
   # labels
-  names=NULL, main=NULL, legend.x="topright",
+  names=NULL, main=NULL, legend.x="topright", format.names=TRUE,
   # plotting controls
   add=FALSE, plot.it=TRUE, tplot=TRUE, ...
 ) {
@@ -198,6 +198,17 @@
       }
     }
 
+    ## apply formatting to chemical formulas 20170204
+    if(format.names) {
+      exprnames <- as.expression(names)
+      for(i in seq_along(exprnames)) {
+        # can the name be parsed as a chemical formula?
+        mtry <- suppressWarnings(try(makeup(exprnames[[i]]), TRUE))
+        if(!identical(class(mtry), "try-error")) exprnames[[i]] <- expr.species(exprnames[[i]])
+      }
+      names <- exprnames
+    }
+
     if(nd==0) {
 
       ### 0-D diagram - bar graph of properties of species or reactions

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2017-02-04 12:55:30 UTC (rev 127)
+++ pkg/CHNOSZ/inst/NEWS	2017-02-04 14:11:59 UTC (rev 128)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.0.8-17 (2017-02-04)
+CHANGES IN CHNOSZ 1.0.8-18 (2017-02-04)
 ---------------------------------------
 
 - Add "AA" as a keyword for preset species in basis() (cysteine,
@@ -41,6 +41,9 @@
 
 - Replace anintro.Rnw (Sweave) with updated anintro.Rmd (knitr, tufte).
 
+- diagram() applies formatting (subscripts and superscripts) to names
+  that parse as chemical formulas; use `format.names` to disable.
+
 CHANGES IN CHNOSZ 1.0.8 (2016-05-28)
 ------------------------------------
 

Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd	2017-02-04 12:55:30 UTC (rev 127)
+++ pkg/CHNOSZ/man/diagram.Rd	2017-02-04 14:11:59 UTC (rev 128)
@@ -15,8 +15,8 @@
     cex=par("cex"), cex.names=1, cex.axis=par("cex"),
     lty=NULL, lwd=par("lwd"), dotted=NULL,
     bg=par("bg"), col=par("col"), col.names=par("col"), fill=NULL,
-    names=NULL, main=NULL, legend.x="topright", add=FALSE, plot.it=TRUE,
-    tplot=TRUE, ...)
+    names=NULL, main=NULL, legend.x="topright", format.names=TRUE,
+    add=FALSE, plot.it=TRUE, tplot=TRUE, ...)
   strip(affinity, ispecies = NULL, col = NULL, ns = NULL, 
     xticks = NULL, ymin = -0.2, xpad = 1, cex.names = 0.7)
   find.tp(x)
@@ -52,6 +52,7 @@
   \item{names}{character, names of species for activity lines or predominance fields}
   \item{main}{character, a main \code{\link{title}} for the plot; \code{NULL} means to plot no title}
   \item{legend.x}{character, description of legend placement passed to \code{\link{legend}}}
+  \item{format.names}{logical, apply formatting to chemical formulas?}
   \item{add}{logical, add to current plot?}
   \item{plot.it}{logical, make a plot?}
   \item{tplot}{logical, set up plot with \code{\link{thermo.plot.new}}?}

Modified: pkg/CHNOSZ/vignettes/anintro.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/anintro.Rmd	2017-02-04 12:55:30 UTC (rev 127)
+++ pkg/CHNOSZ/vignettes/anintro.Rmd	2017-02-04 14:11:59 UTC (rev 128)
@@ -449,7 +449,7 @@
 basis("CHNOS+")
 ```
 ```{r sulfur_species}
-species(c("SO4-2", "HS-", "H2S", "HSO4-"))
+species(c("H2S", "HS-", "HSO4-", "SO4-2"))
 ```
 
 There we used <span style="color:red">`basis()`</span> with a keyword to identify a preset basis definition.
@@ -494,10 +494,10 @@
 
 ```{r EhpH_plot_color, fig.margin=TRUE, fig.width=4, fig.height=4, smallish.mar=TRUE, dpi=50, out.width="100%", echo=FALSE, message=FALSE, cache=TRUE}
 diagram(a, fill="terrain", lwd=3, lty=3,
-        names=c("sulfate", "bisulfide", "hydrogen sulfide", "bisulfate"),
+        names=c("hydrogen sulfide", "bisulfide", "bisulfate", "sulfate"),
         tplot=FALSE, main="sulfur species, 25 °C", bty="n")
 ```
-The default colors for diagrams shown on screen are R's "heat colors".
+The default colors for diagrams shown on the screen are R's "heat colors".
 Some arguments in `diagram()` can be used to control the color, labels, and lines, and title (`main`).
 The `tplot` argument turns off plot customizations used in CHNOSZ.
 Additional arguments can be passed via `...`; here, we use that to remove the box around the plot:
@@ -511,7 +511,7 @@
 These diagrams are made by constructing individual diagrams for the possible basis species.
 The individual diagrams are then combined, each one contributing to the final diagram only in the range of stability of the corresponding basis species.
 
-Here, we use the `mosaic()` function in CHNOSZ to make a diagram for aqueous species and minerals in the Cu-S-Cl-H<sub>2</sub>O system, similar Figure 5a of @CPCC17.
+Here, we use the `mosaic()` function in CHNOSZ to make a diagram for aqueous species and minerals in the Cu-S-Cl-H<sub>2</sub>O system, similar to Figure 5a of @CPCC17.
 The key argument is `bases`, which identifies the candidate basis species (starting with the one in the current basis set).
 The other arguments, like those of `affinity()`, specify the ranges of the variables.
 



More information about the CHNOSZ-commits mailing list