[CHNOSZ-commits] r18 - pkg/CHNOSZ/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 23 03:46:50 CEST 2012


Author: jedick
Date: 2012-09-23 03:46:49 +0200 (Sun, 23 Sep 2012)
New Revision: 18

Modified:
   pkg/CHNOSZ/R/basis.R
   pkg/CHNOSZ/R/species.R
   pkg/CHNOSZ/R/util.affinity.R
   pkg/CHNOSZ/R/util.args.R
Log:
per R-devel, stay away from rep(NULL) with length.out > 0 and array(dim=numeric(0))


Modified: pkg/CHNOSZ/R/basis.R
===================================================================
--- pkg/CHNOSZ/R/basis.R	2012-09-21 13:40:31 UTC (rev 17)
+++ pkg/CHNOSZ/R/basis.R	2012-09-23 01:46:49 UTC (rev 18)
@@ -137,13 +137,13 @@
   if(!length(unique(species))==length(species)) stop("species names are not unique")
   ## processing 'state' and 'logact' arguments
   # they should be same length as species
-  state <- rep(state, length.out=length(species))
-  logact <- rep(logact, length.out=length(species))
+  if(!is.null(state)) state <- rep(state, length.out=length(species))
+  if(!is.null(logact)) logact <- rep(logact, length.out=length(species))
   # results should be identical for
   # basis(c('H2O','CO2','H2'), rep('aq',3), c(0,-3,-3))
   # basis(c('H2O','CO2','H2'), c(0,-3,-3), rep('aq',3))
   # first of all, do we have a third argument?
-  if(!is.null(logact[1])) {
+  if(!is.null(logact)) {
     # does the 3rd argument look like states?
     if(is.character(logact[1])) {
       # swap the arguments into their correct places

Modified: pkg/CHNOSZ/R/species.R
===================================================================
--- pkg/CHNOSZ/R/species.R	2012-09-21 13:40:31 UTC (rev 17)
+++ pkg/CHNOSZ/R/species.R	2012-09-23 01:46:49 UTC (rev 18)
@@ -90,8 +90,8 @@
   # if no species are given use all of them if available
   if(is.null(species) & !is.null(thermo$species)) species <- 1:nrow(thermo$species)
 
-  if(length(species) > length(state)) state <- rep(state,length.out=length(species)) else 
-  if(length(state) > length(species)) species <- rep(species,length.out=length(state))
+  if(length(species) > length(state) & !is.null(state)) state <- rep(state,length.out=length(species)) else 
+  if(length(state) > length(species) & !is.null(species)) species <- rep(species,length.out=length(state))
 
   # if they don't look like states (aq,gas,cr) or activities (numeric), 
   # use them as a suffix for species name (e.g., a protein-organism)

Modified: pkg/CHNOSZ/R/util.affinity.R
===================================================================
--- pkg/CHNOSZ/R/util.affinity.R	2012-09-21 13:40:31 UTC (rev 17)
+++ pkg/CHNOSZ/R/util.affinity.R	2012-09-23 01:46:49 UTC (rev 18)
@@ -426,11 +426,13 @@
     # what are the values of ionization affinity for this protein
     thisA <- A[, i]
     # apply the dimensions of T-P-pH
-    thisA <- array(thisA, TPpHdim)
+    tpphdim <- TPpHdim
+    if(length(tpphdim)==0) tpphdim <- 1
+    thisA <- array(thisA, tpphdim)
     # grow into the dimensions of all vars
-    thisA <- array(thisA, c(TPpHdim, otherdim))
-    # even if we're in zero dimensions, we're still a point
-    if(is.null(dim(thisA))) dim(thisA) <- 1
+    alldim <- c(TPpHdim, otherdim)
+    if(length(alldim)==0) alldim <- 1
+    thisA <- array(thisA, alldim)
     # now permute the array to put dimensions in same order as the variables
     thisA <- aperm(thisA, perm)
     # store in output list

Modified: pkg/CHNOSZ/R/util.args.R
===================================================================
--- pkg/CHNOSZ/R/util.args.R	2012-09-21 13:40:31 UTC (rev 17)
+++ pkg/CHNOSZ/R/util.args.R	2012-09-23 01:46:49 UTC (rev 18)
@@ -44,8 +44,8 @@
           warning('TP.args: NAs in Psat (likely T > Tc where Tc = 647.096 K)',call.=FALSE)
     }
   }
-  if(length(P) < length(T)) P <- rep(P, length.out=length(T))
-  else if(length(T) < length(P)) T <- rep(T, length.out=length(P))
+  if(length(P) < length(T) & !is.null(P)) P <- rep(P, length.out=length(T))
+  else if(length(T) < length(P) & !is.null(T)) T <- rep(T, length.out=length(P))
   # something we do here so the SUPCRT water calculations work
   T[T==273.15] <- 273.16
   return(list(T=T,P=P))



More information about the CHNOSZ-commits mailing list