[CHNOSZ-commits] r421 - in pkg/CHNOSZ: . R inst man tests/testthat
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Mar 4 09:13:34 CET 2019
Author: jedick
Date: 2019-03-04 09:13:33 +0100 (Mon, 04 Mar 2019)
New Revision: 421
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/examples.R
pkg/CHNOSZ/R/retrieve.R
pkg/CHNOSZ/inst/CHECKLIST
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/retrieve.Rd
pkg/CHNOSZ/tests/testthat/test-retrieve.R
Log:
retrieve(): update stoichiometric matrix if database changes
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2019-03-03 06:54:49 UTC (rev 420)
+++ pkg/CHNOSZ/DESCRIPTION 2019-03-04 08:13:33 UTC (rev 421)
@@ -1,6 +1,6 @@
-Date: 2019-03-03
+Date: 2019-03-04
Package: CHNOSZ
-Version: 1.3.1-1
+Version: 1.3.1-2
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/examples.R
===================================================================
--- pkg/CHNOSZ/R/examples.R 2019-03-03 06:54:49 UTC (rev 420)
+++ pkg/CHNOSZ/R/examples.R 2019-03-04 08:13:33 UTC (rev 421)
@@ -8,7 +8,8 @@
topics <- c("thermo", "examples",
"util.array", "util.blast", "util.data", "util.expression",
"util.fasta", "util.formula", "util.matrix", "util.misc", "util.seq", "util.units",
- "util.water", "taxonomy", "info", "retrieve", "protein.info", "hkf", "water", "IAPWS95", "subcrt", "berman",
+ "util.water", "taxonomy", "info", "retrieve", "add.obigt", "protein.info",
+ "hkf", "water", "IAPWS95", "subcrt", "berman",
"makeup", "basis", "swap.basis", "species", "affinity", "solubility", "equilibrate",
"diagram", "buffer", "nonideal", "NaCl", "add.protein", "protein", "ionize.aa", "yeast.aa",
"objective", "revisit", "EOSregress", "wjd")
Modified: pkg/CHNOSZ/R/retrieve.R
===================================================================
--- pkg/CHNOSZ/R/retrieve.R 2019-03-03 06:54:49 UTC (rev 420)
+++ pkg/CHNOSZ/R/retrieve.R 2019-03-04 08:13:33 UTC (rev 421)
@@ -2,23 +2,38 @@
# retrieve species with given elements
# 20190214 initial version
# 20190224 use ... for multiple arguments (define a chemical system)
+# 20190304 update the stoichiometric matrix instead of doing a full recalculation when the database changes
retrieve <- function(..., state = NULL, add.charge = TRUE, hide.groups = TRUE, req1 = FALSE) {
## stoichiometric matrix
# what are the formulas of species in the current database?
formula <- thermo()$obigt$formula
- # get a previously calculated stoichiometric matrix, if it matches the current database
+ # get a previously calculated stoichiometric matrix
stoich <- thermo()$stoich
- if(!is.null(stoich)) {
- # if it doesn't match the current database, don't use it
- if(!identical(rownames(stoich), formula)) stoich <- NULL
- }
- if(is.null(stoich)) {
- # Create the stoichiometric matrix for the current database
- # and suppress warning messages about missing elements
- message("retrieve: creating stoichiometric matrix")
- # NOTE: row names are the formulas, so we can detect if the database changes
- stoich <- suppressWarnings(i2A(formula))
+ # if it doesn't match the current database, update it
+ if(!identical(rownames(stoich), formula)) {
+ message("retrieve: updating stoichiometric matrix")
+ # first put rows in the right order for the current database
+ istoich <- match(formula, rownames(stoich))
+ stoich <- stoich[na.omit(istoich), ]
+ # deal with any missing formulas
+ if(any(is.na(istoich))) {
+ # convert the stoichiometric matrix to data frame with a 'formula' column
+ oldstoich <- cbind(formula = rownames(stoich), as.data.frame(stoich))
+ # get the stoichiometry of the additional formulas
+ # and suppress warning messages about missing elements
+ addstoich <- suppressWarnings(i2A(formula[is.na(istoich)]))
+ addstoich <- cbind(formula = rownames(addstoich), as.data.frame(addstoich))
+ # merge the old and added stoichiometries, and assign 0 for missing elements in either one
+ newstoich <- merge(oldstoich, addstoich, all = TRUE)
+ newstoich[is.na(newstoich)] <- 0
+ # convert the data frame to matrix with rownames corresponding to formulas
+ stoich <- as.matrix(newstoich[, 2:ncol(newstoich)])
+ rownames(stoich) <- newstoich$formula
+ # put rows in the right order for the current database
+ istoich <- match(formula, rownames(stoich))
+ stoich <- stoich[istoich, ]
+ }
# store the stoichiometric matrix for later calculations
thermo("stoich" = stoich)
}
Modified: pkg/CHNOSZ/inst/CHECKLIST
===================================================================
--- pkg/CHNOSZ/inst/CHECKLIST 2019-03-03 06:54:49 UTC (rev 420)
+++ pkg/CHNOSZ/inst/CHECKLIST 2019-03-04 08:13:33 UTC (rev 421)
@@ -2,7 +2,7 @@
release checklist for CHNOSZ
****************************
-- run examples() and demos() to check their output
+- run examples() and demos() and inspect their output (especially plots)
- check output of demo("sources") to make sure all data sources are cited
@@ -37,7 +37,7 @@
- check reverse dependencies on CRAN: LipidMS, canprot, ecipex, iemisc as of 2019-02-09
-OTHER THINGS TO WORK ON:
+OTHER THINGS TO DO (depending on changes made in development):
- update list of documentation topics in examples() with any new ones
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2019-03-03 06:54:49 UTC (rev 420)
+++ pkg/CHNOSZ/inst/NEWS 2019-03-04 08:13:33 UTC (rev 421)
@@ -1,10 +1,13 @@
-CHANGES IN CHNOSZ 1.3.1-1 (2019-03-03)
+CHANGES IN CHNOSZ 1.3.1-2 (2019-03-04)
--------------------------------------
-- Add thermo/stoich.csv.xz (stored as thermo()$stoich), containing a
+- Add thermo/stoich.csv.xz (loaded as thermo()$stoich), containing a
precalculated stochiometric matrix for the default database, to speed
up retrieve().
+- retrieve() now updates the stoichiometric matrix when the database
+ changes, instead of performing a full recalculation.
+
CHANGES IN CHNOSZ 1.3.1 (2019-03-02)
------------------------------------
Modified: pkg/CHNOSZ/man/retrieve.Rd
===================================================================
--- pkg/CHNOSZ/man/retrieve.Rd 2019-03-03 06:54:49 UTC (rev 420)
+++ pkg/CHNOSZ/man/retrieve.Rd 2019-03-04 08:13:33 UTC (rev 421)
@@ -37,7 +37,7 @@
A special argument value \samp{all} can be used to retrieve all species in the thermodynamic database, including filtering on state and hiding of the groups.
To speed up operation, the function uses a precalculated stoichiometric matrix for the default database, which is loaded with the package (see \code{\link{thermo}}).
-If the function detects a change to any chemical formulas in database, it triggers a recalculation using \code{\link{i2A}}.
+If the function detects a change to any chemical formulas in database, it updates the stoichiometric matrix using \code{\link{i2A}}.
}
\seealso{
Modified: pkg/CHNOSZ/tests/testthat/test-retrieve.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-retrieve.R 2019-03-03 06:54:49 UTC (rev 420)
+++ pkg/CHNOSZ/tests/testthat/test-retrieve.R 2019-03-04 08:13:33 UTC (rev 421)
@@ -18,6 +18,6 @@
expect_error(retrieve(c("A", "B", "C", "D")), '"A", "D" are not elements')
# this should recalculate the stoichiometric matrix
add.obigt("SUPCRT92")
- expect_message(retrieve("Ti"), "creating stoichiometric matrix")
+ expect_message(retrieve("Ti"), "updating stoichiometric matrix")
reset()
})
More information about the CHNOSZ-commits
mailing list