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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Oct 27 16:49:32 CEST 2017


Author: jedick
Date: 2017-10-27 16:49:32 +0200 (Fri, 27 Oct 2017)
New Revision: 268

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/R/util.expression.R
   pkg/CHNOSZ/demo/DEW.R
   pkg/CHNOSZ/man/util.expression.Rd
   pkg/CHNOSZ/tests/testthat/test-logmolality.R
Log:
adjust plot labels


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2017-10-25 15:50:57 UTC (rev 267)
+++ pkg/CHNOSZ/DESCRIPTION	2017-10-27 14:49:32 UTC (rev 268)
@@ -1,6 +1,6 @@
-Date: 2017-10-25
+Date: 2017-10-27
 Package: CHNOSZ
-Version: 1.1.0-66
+Version: 1.1.0-67
 Title: Thermodynamic Calculations for Geobiochemistry
 Author: Jeffrey Dick
 Maintainer: Jeffrey Dick <j3ffdick at gmail.com>

Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R	2017-10-25 15:50:57 UTC (rev 267)
+++ pkg/CHNOSZ/R/diagram.R	2017-10-27 14:49:32 UTC (rev 268)
@@ -71,10 +71,11 @@
       eout$values[[i]] / n.balance[i]
     })
     plotvar <- eout$property
-    # we change 'A' to 'A/2.303RT' so the axis label is made correctly
+    # we change 'A' to 'A/(2.303RT)' so the axis label is made correctly
+    # 20171027 use parentheses to avoid ambiguity about order of operations
     if(plotvar=="A") {
-      plotvar <- "A/2.303RT"
-      message("diagram: plotting A/2.303RT / n.balance (maximum affinity method for 2-D diagrams)")
+      plotvar <- "A/(2.303RT)"
+      message("diagram: plotting A/(2.303RT) / n.balance (maximum affinity method for 2-D diagrams)")
     } else message(paste("diagram: plotting", plotvar, " / n.balance"))
   }
 
@@ -145,7 +146,7 @@
 
   ## identify predominant species
   predominant <- NA
-  if(plotvar %in% c("loga.equil", "alpha", "A/2.303RT")) {
+  if(plotvar %in% c("loga.equil", "alpha", "A/(2.303RT)")) {
     pv <- plotvals
     # some additional steps for affinity values, but not for equilibrated activities
     if(eout.is.aout) {
@@ -274,6 +275,7 @@
         # 20120521: use legend.x=NA to label lines rather than make legend
         if(is.na(legend.x)) {
           maxvals <- do.call(pmax, pv)
+          dy <- rep(dy, length.out=length(plotvals))
           for(i in 1:length(plotvals)) {
             # y-values for this line
             myvals <- as.numeric(plotvals[[i]])
@@ -303,7 +305,7 @@
               }
             }
             # also include y-offset (dy) and y-adjustment (labels bottom-aligned with the line)
-            text(xvalues[imax], plotvals[[i]][imax] + dy, labels=names[i], adj=c(thisadj, 0))
+            text(xvalues[imax], plotvals[[i]][imax] + dy[i], labels=names[i], adj=c(thisadj, 0), cex=cex.names)
           }
         } else legend(x=legend.x, lty=lty, legend=names, col=col, cex=cex.names, lwd=lwd, ...)
       }

Modified: pkg/CHNOSZ/R/util.expression.R
===================================================================
--- pkg/CHNOSZ/R/util.expression.R	2017-10-25 15:50:57 UTC (rev 267)
+++ pkg/CHNOSZ/R/util.expression.R	2017-10-27 14:49:32 UTC (rev 268)
@@ -99,10 +99,12 @@
     # p for subscript italic P (in Cp)
     # 0 for degree sign (but not immediately following a number e.g. 2.303)
     # l for subscript small lambda
+    # ' for prime symbol (like "minute")
     if(thischar=='D') thisexpr <- substitute(Delta)
     if(thischar=='p') thisexpr <- substitute(a[italic(P)], list(a=""))
     if(thischar=='0' & !can.be.numeric(prevchar)) thisexpr <- substitute(degree)
     if(thischar=='l') thisexpr <- substitute(a[lambda], list(a=""))
+    if(thischar=="'") thisexpr <- substitute(minute)
     # put it together
     expr <- substitute(a*b, list(a=expr, b=thisexpr))
   }

Modified: pkg/CHNOSZ/demo/DEW.R
===================================================================
--- pkg/CHNOSZ/demo/DEW.R	2017-10-25 15:50:57 UTC (rev 267)
+++ pkg/CHNOSZ/demo/DEW.R	2017-10-27 14:49:32 UTC (rev 268)
@@ -170,7 +170,7 @@
 names[c(4, 5, 7, 9)] <- ""
 col <- rep("black", length(names))
 col[c(1, 3, 6, 8, 10)] <- c("red", "darkgreen", "purple", "orange", "navyblue")
-diagram(e, alpha = "balance", ylab = "carbon fraction", names = names, col = col, ylim = c(0, 0.8), ylab="carbon fraction")
+diagram(e, alpha = "balance", ylab = "carbon fraction", names = names, col = col, ylim = c(0, 0.8))
 
 ## add legend and title
 ltxt1 <- "P = 50000 bar"

Modified: pkg/CHNOSZ/man/util.expression.Rd
===================================================================
--- pkg/CHNOSZ/man/util.expression.Rd	2017-10-25 15:50:57 UTC (rev 267)
+++ pkg/CHNOSZ/man/util.expression.Rd	2017-10-27 14:49:32 UTC (rev 268)
@@ -70,6 +70,7 @@
      \samp{p} \tab subscript italic P (for isobaric heat capacity) \cr
      \samp{0} \tab degree sign (for a standard-state property) \cr  
      \samp{l} \tab subscript lambda \cr  
+     \samp{'} \tab prime symbol \cr  
   }
 
 A \samp{0} gets interpreted as a degree sign only if it does not immediately follow a number (so that e.g. \samp{2.303} can be included in an expression).

Modified: pkg/CHNOSZ/tests/testthat/test-logmolality.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-logmolality.R	2017-10-25 15:50:57 UTC (rev 267)
+++ pkg/CHNOSZ/tests/testthat/test-logmolality.R	2017-10-27 14:49:32 UTC (rev 268)
@@ -16,8 +16,7 @@
   # we get that loggam(H+)=0 and loggam(HCO3-)=-0.189
   expect_equal(nonid[[2]]$loggam, loggam)
 
-  ## take-home lesson 0: with default settings,
-  ## the activity coefficient of H+ is always 1
+  ## take-home message -1: with default settings, the activity coefficient of H+ is always 1
 
   # how do activity coefficient affect the value of G?
   # let's step back and look at the *standard Gibbs energy* at IS = 0
@@ -28,7 +27,7 @@
   # by an amount determined by the activity coefficient
   expect_equal(out1[[2]]$G - out0[[2]]$G, -convert(loggam, "G"))
 
-  ## take-home lesson 1.5: setting IS in subcrt() gives apparent standard Gibbs energy
+  ## take-home message 0: setting IS in subcrt() gives apparent standard Gibbs energy
 
   # now, what is the equilibrium constant for the reaction CO2 + H2O = H+ + HCO3-?
   # (this is the standard state property at IS=0)
@@ -57,7 +56,7 @@
   A1subcrt <- subcrt(c("CO2", "H2O", "H+", "HCO3-"), c(-1, -1, 1, 1), T=25, logact=c(-3, 0, -7, -3), IS=1)$out$A
   expect_equal(A1subcrt, A1manual)
 
-  ## take-home lesson 1: using subcrt with IS not equal to zero, the "logact"
+  ## take-home message 1: using subcrt with IS not equal to zero, the "logact"
   ## argument is logmolal in affinity calculations for charged aqueous species
 
   # now, calculate the affinities using affinity()
@@ -76,7 +75,7 @@
   A1affinity <- -convert(a1$values[[2]], "G")
   expect_equal(A1affinity[[1]], A1subcrt)
 
-  ## take-home lesson 2: using affinity() with IS not equal to zero, the "logact"
+  ## take-home message 2: using affinity() with IS not equal to zero, the "logact"
   ## set by species() is logmolal in affinity calculations for charged aqueous species
 
   # now, swap HCO3- for CO2 in the basis
@@ -102,7 +101,7 @@
   expect_equal(ACO2_0manual, ACO2_0affinity[[1]])
   expect_equal(ACO2_1manual, ACO2_1affinity[[1]])
 
-  ## take-home lesson 3: using affinity() with IS not equal to zero, the "logact"
+  ## take-home message 3: using affinity() with IS not equal to zero, the "logact"
   ## set by basis() is logmolal in affinity calculations for charged aqueous species
 
   # now look at equilibrate()
@@ -119,6 +118,6 @@
   Aeq1 <- -convert(logK - logQeq1, "G") # zero!
   expect_equal(Aeq1[[1]], 0)
 
-  ## take-home lesson 4: using affinity() with IS not equal to zero, the "loga.equil"
+  ## take-home message 4: using affinity() with IS not equal to zero, the "loga.equil"
   ## returned by equilibrate() is logmolal for speciation calculations with charged aqueous species
 })



More information about the CHNOSZ-commits mailing list