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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Feb 24 14:48:00 CET 2019


Author: jedick
Date: 2019-02-24 14:48:00 +0100 (Sun, 24 Feb 2019)
New Revision: 410

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/add.obigt.R
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/demo/copper.R
   pkg/CHNOSZ/demo/glycinate.R
   pkg/CHNOSZ/demo/lambda.R
   pkg/CHNOSZ/man/add.obigt.Rd
   pkg/CHNOSZ/tests/testthat/test-diagram.R
Log:
some fixups for demos


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2019-02-23 23:25:27 UTC (rev 409)
+++ pkg/CHNOSZ/DESCRIPTION	2019-02-24 13:48:00 UTC (rev 410)
@@ -1,6 +1,6 @@
-Date: 2019-02-23
+Date: 2019-02-24
 Package: CHNOSZ
-Version: 1.2.0-17
+Version: 1.2.0-18
 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	2019-02-23 23:25:27 UTC (rev 409)
+++ pkg/CHNOSZ/R/add.obigt.R	2019-02-24 13:48:00 UTC (rev 410)
@@ -1,6 +1,9 @@
 # CHNOSZ/add.obigt.R
 # add or change entries in the thermodynamic database
 
+## if this file is interactively sourced, the following are also needed to provide unexported functions:
+#source("info.R")
+
 today <- function() {
   # write today's date in the format used in SUPCRT data files
   # e.g. 13.May.12 for 2012-05-13
@@ -68,6 +71,15 @@
       # transmit the error from makeup
       stop(e)
     }
+    # for aqueous species, supply a value for Z if it is missing, otherwise NA triggers AkDi model 20190224
+    isaq <- newrows$state == "aq"
+    if(any(isaq)) {
+      mnrf <- makeup(newrows$formula)
+      if(nrow(newrows)==1) mnrf <- list(mnrf)
+      Z <- sapply(mnrf, "[", "Z")
+      Z[is.na(Z)] <- 0
+      newrows$z.T[isaq] <- Z[isaq]
+    }
     # assign to thermo$obigt
     thermo$obigt <- rbind(thermo$obigt, newrows)
     rownames(thermo$obigt) <- NULL

Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R	2019-02-23 23:25:27 UTC (rev 409)
+++ pkg/CHNOSZ/R/diagram.R	2019-02-24 13:48:00 UTC (rev 410)
@@ -522,8 +522,8 @@
         # calculate coordinates for field labels
         # revisions: 20091116 for speed, 20190223 work with user-specified xlim and ylim
         namesx <- namesy <- rep(NA, length(names))
-        inames <- logical(length(names))
-        for(i in seq_along(names)) {
+        # even if 'names' is NULL, we run the loop in order to generate namesx and namesy for the output 20190225
+        for(i in seq_along(groups)) {
           this <- which(out==i, arr.ind=TRUE)
           if(length(this)==0) next
           xsth <- xs[this[, 2]]
@@ -536,11 +536,9 @@
           if(length(xsth)==0 | length(ysth)==0) next
           namesx[i] <- mean(xsth)
           namesy[i] <- mean(ysth)
-          inames[i] <- TRUE
         }
         # fields that really exist on the plot
-        inames <- !is.na(namesx)
-        if(!is.null(names) & any(inames)) text(namesx, namesy, labels=names[inames], cex=cex.names, col=col.names[inames], font=font, family=family)
+        if(!is.null(names)) text(namesx, namesy, labels=names, cex=cex.names, col=col.names, font=font, family=family)
         return(list(namesx=namesx, namesy=namesy))
       }
 

Modified: pkg/CHNOSZ/demo/copper.R
===================================================================
--- pkg/CHNOSZ/demo/copper.R	2019-02-23 23:25:27 UTC (rev 409)
+++ pkg/CHNOSZ/demo/copper.R	2019-02-24 13:48:00 UTC (rev 410)
@@ -52,7 +52,7 @@
   if(names[i]=="HCu(Gly)+2") srt <- 90
   if(names[i]=="HCu(Gly)+2") dx <- -0.2
   if(names[i]=="Cu(Gly)+") srt <- 90
-  text(d$namesx[i]+dx, d$namesy[i]+dy, lab, srt=srt)
+  text(na.omit(d$namesx)[i]+dx, na.omit(d$namesy)[i]+dy, lab, srt=srt)
 }
 
 # add glycine ionization lines

Modified: pkg/CHNOSZ/demo/glycinate.R
===================================================================
--- pkg/CHNOSZ/demo/glycinate.R	2019-02-23 23:25:27 UTC (rev 409)
+++ pkg/CHNOSZ/demo/glycinate.R	2019-02-24 13:48:00 UTC (rev 410)
@@ -34,6 +34,7 @@
 reset()
 
 # set up the plots
+opar <- par(no.readonly = TRUE)
 layout(matrix(1:6, byrow = TRUE, nrow = 2), widths = c(2, 2, 1))
 par(mar = c(4, 3.2, 2.5, 0.5), mgp = c(2.1, 1, 0), las = 1, cex = 0.8)
 xlab <- axis.label("T")
@@ -66,3 +67,4 @@
 par(xpd = NA)
 legend("right", as.expression(lapply(mo, expr.species)), lty = 1, col = 1:5, bty = "n", cex = 1.2, lwd = 2)
 par(xpd = FALSE)
+par(opar)

Modified: pkg/CHNOSZ/demo/lambda.R
===================================================================
--- pkg/CHNOSZ/demo/lambda.R	2019-02-23 23:25:27 UTC (rev 409)
+++ pkg/CHNOSZ/demo/lambda.R	2019-02-24 13:48:00 UTC (rev 410)
@@ -84,4 +84,5 @@
 plot(Pkb, Qz_lambda$S, type="l", ylim=c(0, 3), ylab=axis.label("DlS"), xlab=Plab)
 labplot("f")
 
+reset()
 par(opar)

Modified: pkg/CHNOSZ/man/add.obigt.Rd
===================================================================
--- pkg/CHNOSZ/man/add.obigt.Rd	2019-02-23 23:25:27 UTC (rev 409)
+++ pkg/CHNOSZ/man/add.obigt.Rd	2019-02-24 13:48:00 UTC (rev 410)
@@ -51,7 +51,7 @@
 An error results if the formula is not valid (i.e. can not be parsed by\code{\link{makeup}}).
 Additional arguments refer to the name of the property(s) to be updated and are matched to any part of compound column names in \code{\link{thermo}$obigt}, such as \samp{z} or \samp{T} in \samp{z.T}.
 Unless \samp{state} is specified as one of the properties, its value is taken from \code{thermo$opt$state}.
-When adding species, properties that are not specified become NA (except for \samp{state}).
+When adding species, properties that are not specified become NA, except for \samp{state}, which takes a default value from \code{thermo$opt$state}, and \samp{z.T}, which for aqueous species is set to the charge calculated from the chemical formula (otherwise, NA charge for newly added species would trigger the \code{\link{AkDi}} model).
 The values provided should be in the units specifed in the documentation for the \code{thermo} data object, including any order-of-magnitude scaling factors.
 
 \code{today} returns the current date in the format adopted for \code{thermo$obigt} (inherited from SUPCRT-format data files) e.g. \samp{13.May.12} for May 13, 2012.

Modified: pkg/CHNOSZ/tests/testthat/test-diagram.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-diagram.R	2019-02-23 23:25:27 UTC (rev 409)
+++ pkg/CHNOSZ/tests/testthat/test-diagram.R	2019-02-24 13:48:00 UTC (rev 410)
@@ -110,7 +110,7 @@
 #  # reduce y-range to exclude hematite
 #  d <- diagram(a, fill="heat", xlim=NULL, ylim=c(-90, -50), plot.it=FALSE)
 #  expect_equal(sum(is.na(d$namesx)), 1)
-#  # reduce x-range to exclude pyrrhotite
+#  # reduce x-range to exclude pyrite
 #  d <- diagram(a, fill="heat", xlim=c(-50, -20), ylim=c(-90, -50), plot.it=FALSE)
 #  expect_equal(sum(is.na(d$namesx)), 2)
 #})



More information about the CHNOSZ-commits mailing list