[CHNOSZ-commits] r189 - in pkg/CHNOSZ: . R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 27 07:24:50 CEST 2017


Author: jedick
Date: 2017-04-27 07:24:50 +0200 (Thu, 27 Apr 2017)
New Revision: 189

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/read.expr.R
   pkg/CHNOSZ/R/util.character.R
   pkg/CHNOSZ/R/util.formula.R
   pkg/CHNOSZ/inst/NEWS
Log:
avoid suppressWarnings (they still appear using testthat)


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2017-04-27 02:30:51 UTC (rev 188)
+++ pkg/CHNOSZ/DESCRIPTION	2017-04-27 05:24:50 UTC (rev 189)
@@ -1,6 +1,6 @@
 Date: 2017-04-27
 Package: CHNOSZ
-Version: 1.0.8-77
+Version: 1.0.8-78
 Title: Chemical Thermodynamics and Activity Diagrams
 Author: Jeffrey Dick
 Maintainer: Jeffrey Dick <j3ffdick at gmail.com>

Modified: pkg/CHNOSZ/R/read.expr.R
===================================================================
--- pkg/CHNOSZ/R/read.expr.R	2017-04-27 02:30:51 UTC (rev 188)
+++ pkg/CHNOSZ/R/read.expr.R	2017-04-27 05:24:50 UTC (rev 189)
@@ -12,9 +12,7 @@
   # yeastgfp preprocessing
   ygfp <- read.csv(yfile)
   # convert factors to numeric w/o NA coercion warnings
-  warn <- options(warn=-1)
-  ygfp$abundance <- as.numeric(as.character(ygfp$abundance))
-  options(warn)
+  ygfp$abundance <- as.numeric.nowarn(as.character(ygfp$abundance))
   # if location is NULL, just report on the content of the file
   # and return the names of the locations
   if(is.null(location)) {

Modified: pkg/CHNOSZ/R/util.character.R
===================================================================
--- pkg/CHNOSZ/R/util.character.R	2017-04-27 02:30:51 UTC (rev 188)
+++ pkg/CHNOSZ/R/util.character.R	2017-04-27 05:24:50 UTC (rev 189)
@@ -55,14 +55,26 @@
 # return a value of TRUE or FALSE for each element of x
 can.be.numeric <- function(x) {
   # return FALSE if length of argument is zero
-  if(length(x)==0) return(FALSE)
-  if(length(x)>1) return(as.logical(sapply(x,can.be.numeric)))
-  # don't warn about NAs in as.numeric
-  oldopt <- options(warn=-1)
-  cb <- FALSE
-  if(!is.na(as.numeric(x))) cb <- TRUE
-  if(x %in% c('.','+','-')) cb <- TRUE
-  # let the user have their way
-  options(oldopt)
-  return(cb)
+  if(length(x) == 0) FALSE else
+  if(length(x) > 1) as.logical(sapply(x, can.be.numeric)) else {
+    if(is.numeric(x)) TRUE else
+    if(!is.na(as.numeric.nowarn(x))) TRUE else
+    if(x %in% c('.','+','-')) TRUE else FALSE
+  }
 }
+
+# something like R's as.numeric(), but without the "NAs introduced by coercion" warnings
+# (needed because testthat somehow detects the warnings suppressed by suppressWarnings) 20170427
+as.numeric.nowarn <- function(x) {
+  if(length(x) == 0) numeric() else
+  if(length(x) > 1) sapply(x, as.numeric.nowarn) else
+  # http://stackoverflow.com/questions/12643009/regular-expression-for-floating-point-numbers
+  if(grepl("^[+-]?([0-9]*[.])?[0-9]+$", x)) as.numeric(x) else NA_real_
+}
+
+# convert to integer without NA coercion warnings
+as.integer.nowarn <- function(x) {
+  if(length(x) == 0) integer() else
+  if(length(x) > 1) sapply(x, as.integer.nowarn) else
+  if(grepl("[^0-9]", x)) NA_integer_ else as.integer(x)
+}

Modified: pkg/CHNOSZ/R/util.formula.R
===================================================================
--- pkg/CHNOSZ/R/util.formula.R	2017-04-27 02:30:51 UTC (rev 188)
+++ pkg/CHNOSZ/R/util.formula.R	2017-04-27 05:24:50 UTC (rev 189)
@@ -156,7 +156,7 @@
   # return the values in the argument, or chemical formula(s) 
   # for values that are species indices
   # for numeric values, get the formulas from those rownumbers of thermo$obigt
-  i <- suppressWarnings(as.numeric(formula))
+  i <- as.integer.nowarn(formula)
   # we can't have more than the number of rows in thermo$obigt
   thermo <- get("thermo")
   iover <- i > nrow(thermo$obigt)

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2017-04-27 02:30:51 UTC (rev 188)
+++ pkg/CHNOSZ/inst/NEWS	2017-04-27 05:24:50 UTC (rev 189)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.0.8-77 (2017-04-27)
+CHANGES IN CHNOSZ 1.0.8-78 (2017-04-27)
 ---------------------------------------
 
 DOCUMENTATION:



More information about the CHNOSZ-commits mailing list