[CHNOSZ-commits] r424 - in pkg/CHNOSZ: . R tests/testthat
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Mar 6 04:15:10 CET 2019
Author: jedick
Date: 2019-03-06 04:15:08 +0100 (Wed, 06 Mar 2019)
New Revision: 424
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/retrieve.R
pkg/CHNOSZ/tests/testthat/test-retrieve.R
Log:
retrieve(): error message lists all unrecognized elements in arguments
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2019-03-05 09:00:54 UTC (rev 423)
+++ pkg/CHNOSZ/DESCRIPTION 2019-03-06 03:15:08 UTC (rev 424)
@@ -1,6 +1,6 @@
-Date: 2019-03-05
+Date: 2019-03-06
Package: CHNOSZ
-Version: 1.3.1-4
+Version: 1.3.1-5
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/retrieve.R
===================================================================
--- pkg/CHNOSZ/R/retrieve.R 2019-03-05 09:00:54 UTC (rev 423)
+++ pkg/CHNOSZ/R/retrieve.R 2019-03-06 03:15:08 UTC (rev 424)
@@ -43,6 +43,14 @@
thermo("stoich" = stoich)
}
+ ## generate error for missing element(s)
+ allelements <- c(unlist(elements), unlist(ligands))
+ not.present <- ! allelements %in% c(colnames(stoich), "all")
+ if(any(not.present)) {
+ if(sum(not.present)==1) stop('"', allelements[not.present], '" is not an element that is present in any species in the database')
+ else stop('"', paste(allelements[not.present], collapse='", "'), '" are not elements that are present in any species in the database')
+ }
+
## handle 'ligands' argument
if(!is.null(ligands)) {
@@ -71,7 +79,6 @@
if(identical(element, "all")) {
ispecies[[i]] <- 1:nrow(thermo()$obigt)
} else {
- if(! element %in% colnames(stoich)) stop('"', element, '" is not an element that is present in any species')
# identify the species that have the element
has.element <- rowSums(stoich[, element, drop = FALSE] != 0) == 1
ispecies[[i]] <- which(has.element)
Modified: pkg/CHNOSZ/tests/testthat/test-retrieve.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-retrieve.R 2019-03-05 09:00:54 UTC (rev 423)
+++ pkg/CHNOSZ/tests/testthat/test-retrieve.R 2019-03-06 03:15:08 UTC (rev 424)
@@ -13,7 +13,14 @@
test_that("errors and recalculations produce expected messages", {
expect_error(retrieve(c("A", "B", "C")), '"A" is not an element')
+ expect_error(retrieve(c("A", "B", "C", "D")), '"A", "D" are not elements')
add.obigt("SUPCRT92")
expect_message(retrieve("Ti"), "updating stoichiometric matrix")
reset()
})
+
+test_that("retrieve('all') works", {
+ all1 <- sort(retrieve("all"))
+ all2 <- sort(retrieve(as.list(colnames(thermo()$stoich))))
+ expect_identical(all1, all2)
+})
More information about the CHNOSZ-commits
mailing list