[CHNOSZ-commits] r388 - in pkg/CHNOSZ: . R tests/testthat

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 9 05:54:48 CET 2019


Author: jedick
Date: 2019-02-09 05:54:47 +0100 (Sat, 09 Feb 2019)
New Revision: 388

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/info.R
   pkg/CHNOSZ/tests/testthat/test-info.R
Log:
info(): improve message for info("glycine")


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2019-02-08 09:15:07 UTC (rev 387)
+++ pkg/CHNOSZ/DESCRIPTION	2019-02-09 04:54:47 UTC (rev 388)
@@ -1,6 +1,6 @@
-Date: 2019-02-08
+Date: 2019-02-09
 Package: CHNOSZ
-Version: 1.1.3-95
+Version: 1.1.3-96
 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/info.R
===================================================================
--- pkg/CHNOSZ/R/info.R	2019-02-08 09:15:07 UTC (rev 387)
+++ pkg/CHNOSZ/R/info.R	2019-02-09 04:54:47 UTC (rev 388)
@@ -136,8 +136,13 @@
     mystate <- thermo$obigt$state[ispecies.out]
     ispecies.other <- ispecies[!ispecies %in% ispecies.out]
     otherstates <- thermo$obigt$state[ispecies.other]
+    # for minerals (cr), use the word "phase"; otherwise, use "state" 20190209
+    word <- "state"
     # substitute the mineral name for "cr" 20190121
-    otherstates[otherstates=="cr"] <- thermo$obigt$name[ispecies.other[otherstates=="cr"]]
+    if(mystate == "cr" | sum(otherstates=="cr") > 1) {
+      word <- "phase"
+      otherstates[otherstates=="cr"] <- thermo$obigt$name[ispecies.other[otherstates=="cr"]]
+    }
     transtext <- othertext <- ""
     # we count, but don't show the states for phase transitions (cr2, cr3, etc)
     istrans <- otherstates %in% c("cr2", "cr3", "cr4", "cr5", "cr6", "cr7", "cr8", "cr9")
@@ -146,12 +151,12 @@
       ntrans <- sum(istrans)
       if(ntrans == 1) transtext <- paste(" with", ntrans, "phase transition")
       else if(ntrans > 1) transtext <- paste(" with", ntrans, "phase transitions")
-      # substitute the mineral name for "cr" 20190121
-      mystate <- thermo$obigt$name[ispecies.out]
+      # if it's not already in the species name, substitute the mineral name for "cr" 20190121
+      if(species != thermo$obigt$name[ispecies.out]) mystate <- thermo$obigt$name[ispecies.out]
     }
     otherstates <- otherstates[!istrans]
-    if(length(otherstates) == 1) othertext <- paste0("; other available phase is ", otherstates)
-    if(length(otherstates) > 1) othertext <- paste0("; other available phases are ", paste(otherstates, collapse=", "))
+    if(length(otherstates) == 1) othertext <- paste0("; other available ", word, " is ", otherstates)
+    if(length(otherstates) > 1) othertext <- paste0("; other available ", word, "s are ", paste(otherstates, collapse=", "))
     if(transtext != "" | othertext != "") {
       starttext <- paste0("info.character: found ", species, "(", mystate, ")")
       message(starttext, transtext, othertext)
@@ -253,4 +258,3 @@
   message("info.approx: '", species, "' has no approximate matches")
   return(NA)
 }
-

Modified: pkg/CHNOSZ/tests/testthat/test-info.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-info.R	2019-02-08 09:15:07 UTC (rev 387)
+++ pkg/CHNOSZ/tests/testthat/test-info.R	2019-02-09 04:54:47 UTC (rev 388)
@@ -4,7 +4,9 @@
   expect_equal(info.character("acetate", "cr"), NA)
   expect_message(info.character("acetate", "cr"), "only 'aq' is available")
   expect_message(info.character("methane", "cr"), "only 'aq' 'liq' 'gas' are available")
-  expect_message(info.character("methane"), "other available phases are liq, gas")
+  expect_message(info.character("methane"), "other available states are liq, gas")
+  expect_message(info.character("SiO2", "cr"), "other available phases are")
+  expect_message(info.character("chalcocite"), "found chalcocite\\(cr\\) with 2 phase transitions")
   # H2O is a special case
   expect_equal(info.character("H2O", "aq"), info.character("H2O", "liq"))
 })



More information about the CHNOSZ-commits mailing list