[CHNOSZ-commits] r793 - in pkg/CHNOSZ: . R inst inst/extdata/adds man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 24 02:59:45 CEST 2023


Author: jedick
Date: 2023-06-24 02:59:45 +0200 (Sat, 24 Jun 2023)
New Revision: 793

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/Berman.R
   pkg/CHNOSZ/R/DEW.R
   pkg/CHNOSZ/R/IAPWS95.R
   pkg/CHNOSZ/R/add.OBIGT.R
   pkg/CHNOSZ/R/add.protein.R
   pkg/CHNOSZ/R/affinity.R
   pkg/CHNOSZ/R/basis.R
   pkg/CHNOSZ/R/buffer.R
   pkg/CHNOSZ/R/cgl.R
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/R/equilibrate.R
   pkg/CHNOSZ/R/examples.R
   pkg/CHNOSZ/R/hkf.R
   pkg/CHNOSZ/R/info.R
   pkg/CHNOSZ/R/ionize.aa.R
   pkg/CHNOSZ/R/makeup.R
   pkg/CHNOSZ/R/mix.R
   pkg/CHNOSZ/R/mosaic.R
   pkg/CHNOSZ/R/nonideal.R
   pkg/CHNOSZ/R/palply.R
   pkg/CHNOSZ/R/protein.info.R
   pkg/CHNOSZ/R/retrieve.R
   pkg/CHNOSZ/R/solubility.R
   pkg/CHNOSZ/R/species.R
   pkg/CHNOSZ/R/subcrt.R
   pkg/CHNOSZ/R/swap.basis.R
   pkg/CHNOSZ/R/taxonomy.R
   pkg/CHNOSZ/R/thermo.R
   pkg/CHNOSZ/R/util.affinity.R
   pkg/CHNOSZ/R/util.args.R
   pkg/CHNOSZ/R/util.array.R
   pkg/CHNOSZ/R/util.character.R
   pkg/CHNOSZ/R/util.data.R
   pkg/CHNOSZ/R/util.expression.R
   pkg/CHNOSZ/R/util.fasta.R
   pkg/CHNOSZ/R/util.formula.R
   pkg/CHNOSZ/R/util.misc.R
   pkg/CHNOSZ/R/util.plot.R
   pkg/CHNOSZ/R/util.protein.R
   pkg/CHNOSZ/R/util.seq.R
   pkg/CHNOSZ/R/util.units.R
   pkg/CHNOSZ/R/water.R
   pkg/CHNOSZ/R/zzz.R
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/inst/extdata/adds/OBIGT_check.csv
   pkg/CHNOSZ/man/util.data.Rd
   pkg/CHNOSZ/vignettes/FAQ.Rmd
Log:
Add spaces around equals signs


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/DESCRIPTION	2023-06-24 00:59:45 UTC (rev 793)
@@ -1,6 +1,6 @@
-Date: 2023-06-23
+Date: 2023-06-24
 Package: CHNOSZ
-Version: 2.0.0-12
+Version: 2.0.0-13
 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/Berman.R
===================================================================
--- pkg/CHNOSZ/R/Berman.R	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/R/Berman.R	2023-06-24 00:59:45 UTC (rev 793)
@@ -4,14 +4,14 @@
 #      in the system Na2O-K2O-CaO-MgO-FeO-Fe2O3-Al2O3-SiO2-TiO2-H2O-CO2.
 #      J. Petrol. 29, 445-522. https://doi.org/10.1093/petrology/29.2.445
 
-Berman <- function(name, T = 298.15, P = 1, check.G=FALSE, calc.transition=TRUE, calc.disorder=TRUE) {
+Berman <- function(name, T = 298.15, P = 1, check.G = FALSE, calc.transition = TRUE, calc.disorder = TRUE) {
   # Reference temperature and pressure
   Pr <- 1
   Tr <- 298.15
   # Make T and P the same length
   ncond <- max(length(T), length(P))
-  T <- rep(T, length.out=ncond)
-  P <- rep(P, length.out=ncond)
+  T <- rep(T, length.out = ncond)
+  P <- rep(P, length.out = ncond)
 
   # Get parameters in the Berman equations
   # Start with thermodynamic parameters provided with CHNOSZ
@@ -20,10 +20,10 @@
   userfile <- get("thermo", CHNOSZ)$opt$Berman
   userfileexists <- FALSE
   if(!is.na(userfile)) {
-    if(userfile!="") {
+    if(userfile != "") {
       if(file.exists(userfile)) {
         userfileexists <- TRUE
-        BDat_user <- read.csv(userfile, as.is=TRUE)
+        BDat_user <- read.csv(userfile, as.is = TRUE)
         dat <- rbind(BDat_user, dat)
       } else stop("the file named in thermo()$opt$Berman (", userfile, ") does not exist")
     } 
@@ -38,7 +38,7 @@
   if(missing(name)) return(dat) else {
     # Which row has data for this mineral?
     irow <- which(dat$name == name)
-    if(length(irow)==0) {
+    if(length(irow) == 0) {
       if(userfileexists) stop("Data for ", name, " not available. Please add it to ", userfile)
       if(!userfileexists) stop("Data for ", name, " not available. Please add it to your_data_file.csv and run thermo('opt$Berman' = 'path/to/your_data_file.csv')")
     }
@@ -62,7 +62,7 @@
     Gdiff <- GfPrTr_calc - GfPrTr
     #if(is.na(GfPrTr)) warning(paste0(name, ": GfPrTr(table) is NA"), call.=FALSE)
     if(!is.na(GfPrTr)) if(abs(Gdiff) >= 1000) warning(paste0(name, ": GfPrTr(calc) - GfPrTr(table) is too big! == ",
-                                          round(GfPrTr_calc - GfPrTr), " J/mol"), call.=FALSE)
+                                          round(GfPrTr_calc - GfPrTr), " J/mol"), call. = FALSE)
     # (the tabulated GfPrTr is unused below)
   }
 

Modified: pkg/CHNOSZ/R/DEW.R
===================================================================
--- pkg/CHNOSZ/R/DEW.R	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/R/DEW.R	2023-06-24 00:59:45 UTC (rev 793)
@@ -47,8 +47,8 @@
     calculateDensity
   }
   # Make input pressure and temperature the same length
-  if(length(pressure) < length(temperature)) pressure <- rep(pressure, length.out=length(temperature))
-  if(length(temperature) < length(pressure)) temperature <- rep(temperature, length.out=length(pressure))
+  if(length(pressure) < length(temperature)) pressure <- rep(pressure, length.out = length(temperature))
+  if(length(temperature) < length(pressure)) temperature <- rep(temperature, length.out = length(pressure))
   # Use a loop to process vectorized input
   sapply(1:length(pressure), function(i) myfunction(pressure[i], temperature[i]))
 }
@@ -88,8 +88,8 @@
     GAtOneKb + integral
   }
   # Make input pressure and temperature the same length
-  if(length(pressure) < length(temperature)) pressure <- rep(pressure, length.out=length(temperature))
-  if(length(temperature) < length(pressure)) temperature <- rep(temperature, length.out=length(pressure))
+  if(length(pressure) < length(temperature)) pressure <- rep(pressure, length.out = length(temperature))
+  if(length(temperature) < length(pressure)) temperature <- rep(temperature, length.out = length(pressure))
   # Use a loop to process vectorized input
   sapply(1:length(pressure), function(i) myfunction(pressure[i], temperature[i]))
 }
@@ -223,7 +223,7 @@
   omega <- eta * (Z * Z / re - Z / (3.082 + g))
   # 'If species is hydrogen, the species is neutral, or the pressure is above 6 kb,
   # 'this equation is not necessary because omega is very close to wref.
-  if(Z==0) omega[] <- wref
+  if(Z == 0) omega[] <- wref
   omega[pressure > 6000] <- wref
 }
 

Modified: pkg/CHNOSZ/R/IAPWS95.R
===================================================================
--- pkg/CHNOSZ/R/IAPWS95.R	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/R/IAPWS95.R	2023-06-24 00:59:45 UTC (rev 793)
@@ -1,6 +1,6 @@
 # Calculate properties of water using the IAPWS-95 formulation (Wagner and Pruss, 2002)
 
-IAPWS95 <- function(property,T=298.15,rho=1000) {
+IAPWS95 <- function(property,T = 298.15,rho = 1000) {
   property <- tolower(property)
   # Triple point
   T.triple <- 273.16 # K
@@ -95,7 +95,7 @@
       t <- c(t,get(property[j])())
     }
     t <- data.frame(t)
-    if(j==1) ww <- t else ww <- cbind(ww,t)
+    if(j == 1) ww <- t else ww <- cbind(ww,t)
   }
   colnames(ww) <- property
   return(ww)

Modified: pkg/CHNOSZ/R/add.OBIGT.R
===================================================================
--- pkg/CHNOSZ/R/add.OBIGT.R	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/R/add.OBIGT.R	2023-06-24 00:59:45 UTC (rev 793)
@@ -15,7 +15,7 @@
   if(is.list(args[[1]])) args <- args[[1]]
   if(length(args) < 2) stop("please supply at least a species name and a property to update")
   if(is.null(names(args))) stop("all arguments after the first should be named")
-  if(any(tail(nchar(names(args)), -1)==0)) stop("all arguments after the first should be named")
+  if(any(tail(nchar(names(args)), -1) == 0)) stop("all arguments after the first should be named")
   # If the first argument is numeric, it's the species index
   if(is.numeric(args[[1]][1])) {
     ispecies <- args[[1]]
@@ -23,7 +23,7 @@
     speciesname <- info(ispecies, check.it = FALSE)$name
   } else {
     # If the name of the first argument is missing, assume it's the species name
-    if(names(args)[1]=="") names(args)[1] <- "name"
+    if(names(args)[1] == "") names(args)[1] <- "name"
     speciesname <- args$name
     # Search for this species, use check.protein = FALSE to avoid infinite loop when adding proteins
     # and suppressMessages to not show messages about matches of this name to other states
@@ -33,10 +33,10 @@
       species = args$name, check.protein = FALSE, SIMPLIFY = TRUE, USE.NAMES = FALSE))
   }
   # The column names of thermo()$OBIGT, split at the "."
-  cnames <- c(do.call(rbind, strsplit(colnames(thermo$OBIGT), ".", fixed=TRUE)), colnames(thermo$OBIGT))
+  cnames <- c(do.call(rbind, strsplit(colnames(thermo$OBIGT), ".", fixed = TRUE)), colnames(thermo$OBIGT))
   # The columns we are updating
   icol <- match(names(args), cnames)
-  if(any(is.na(icol))) stop(paste("properties not in thermo$OBIGT:", paste(names(args)[is.na(icol)], collapse=" ")) )
+  if(any(is.na(icol))) stop(paste("properties not in thermo$OBIGT:", paste(names(args)[is.na(icol)], collapse = " ")) )
   # The column numbers for properties that matched after the split
   icol[icol > 44] <- icol[icol > 44] - 44
   icol[icol > 22] <- icol[icol > 22] - 22
@@ -44,7 +44,7 @@
   inew <- which(is.na(ispecies))
   iold <- which(!is.na(ispecies))
   # The arguments as data frame
-  args <- data.frame(args, stringsAsFactors=FALSE)
+  args <- data.frame(args, stringsAsFactors = FALSE)
   if(length(inew) > 0) {
     # The right number of blank rows of thermo()$OBIGT
     newrows <- thermo$OBIGT[1:length(inew), ]
@@ -62,7 +62,7 @@
     namodel <- is.na(newrows$model)
     if(any(namodel)) newrows$model[namodel] <- ifelse(newrows$state[namodel] == "aq", "HKF", "CGL")
     # Now check the formulas
-    e <- tryCatch(makeup(newrows$formula), error=function(e) e)
+    e <- tryCatch(makeup(newrows$formula), error = function(e) e)
     if(inherits(e, "error")) {
       warning("please supply a valid chemical formula as the species name or in the 'formula' argument")
       # Transmit the error from makeup
@@ -76,7 +76,8 @@
     ntotal <- nrow(thermo$OBIGT)
     ispecies[inew] <- (ntotal-length(inew)+1):ntotal
     # Inform user
-    message(paste("mod.OBIGT: added ", newrows$name, "(", newrows$state, ")", " with ", newrows$model, " model and energy units of ", newrows$E_units, sep="", collapse="\n"))
+    message(paste("mod.OBIGT: added ", newrows$name, "(", newrows$state, ")", " with ", newrows$model,
+      " model and energy units of ", newrows$E_units, sep = "", collapse = "\n"))
   }
   if(length(iold) > 0) {
     # Loop over species
@@ -108,19 +109,19 @@
   return(ispecies)
 }
 
-add.OBIGT <- function(file, species=NULL, force=TRUE) {
+add.OBIGT <- function(file, species = NULL, force = TRUE) {
   # Add/replace entries in thermo$OBIGT from values saved in a file
-  # Only replace if force==TRUE
+  # Only replace if force == TRUE
   thermo <- get("thermo", CHNOSZ)
   to1 <- thermo$OBIGT
   id1 <- paste(to1$name,to1$state)
   # We match system files with the file suffixes (.csv) removed
-  sysfiles <- dir(system.file("extdata/OBIGT/", package="CHNOSZ"))
+  sysfiles <- dir(system.file("extdata/OBIGT/", package = "CHNOSZ"))
   sysnosuffix <- sapply(strsplit(sysfiles, "\\."), "[", 1)
   isys <- match(file, sysnosuffix)
-  if(!is.na(isys)) file <- system.file(paste0("extdata/OBIGT/", sysfiles[isys]), package="CHNOSZ")
+  if(!is.na(isys)) file <- system.file(paste0("extdata/OBIGT/", sysfiles[isys]), package = "CHNOSZ")
   # Read data from the file
-  to2 <- read.csv(file, as.is=TRUE)
+  to2 <- read.csv(file, as.is = TRUE)
   Etxt <- paste(unique(to2$E_units), collapse = " and ")
   # Load only selected species if requested
   if(!is.null(species)) {
@@ -127,7 +128,7 @@
     idat <- match(species, to2$name)
     ina <- is.na(idat)
     if(!any(ina)) to2 <- to2[idat, ]
-    else stop(paste("file", file, "doesn't have", paste(species[ina], collapse=", ")))
+    else stop(paste("file", file, "doesn't have", paste(species[ina], collapse = ", ")))
   }
   id2 <- paste(to2$name,to2$state)
   # Check if the data table is compatible with thermo$OBIGT

Modified: pkg/CHNOSZ/R/add.protein.R
===================================================================
--- pkg/CHNOSZ/R/add.protein.R	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/R/add.protein.R	2023-06-24 00:59:45 UTC (rev 793)
@@ -56,7 +56,7 @@
 aasum <- function(aa, abundance = 1, average = FALSE, protein = NULL, organism = NULL) {
   # Returns the sum of the amino acid counts in aa,
   #   multiplied by the abundances of the proteins
-  abundance <- rep(abundance, length.out=nrow(aa))
+  abundance <- rep(abundance, length.out = nrow(aa))
   # Drop any NA rows or abundances
   ina.aa <- is.na(aa$chains)
   ina.ab <- is.na(abundance)

Modified: pkg/CHNOSZ/R/affinity.R
===================================================================
--- pkg/CHNOSZ/R/affinity.R	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/R/affinity.R	2023-06-24 00:59:45 UTC (rev 793)
@@ -12,8 +12,8 @@
 #source("util.data.R")
 #source("species.R")
 
-affinity <- function(..., property=NULL, sout=NULL, exceed.Ttr=FALSE, exceed.rhomin=FALSE,
-  return.buffer=FALSE, return.sout=FALSE, balance="PBB", iprotein=NULL, loga.protein=0, transect = NULL) {
+affinity <- function(..., property = NULL, sout = NULL, exceed.Ttr = FALSE, exceed.rhomin = FALSE,
+  return.buffer = FALSE, return.sout = FALSE, balance = "PBB", iprotein = NULL, loga.protein = 0, transect = NULL) {
   # ...: variables over which to calculate
   # property: what type of energy
   #   (G.basis,G.species,logact.basis,logK,logQ,A)
@@ -34,7 +34,7 @@
   args.orig <- list(...)
   # We can only do anything with at least one argument
   if(length(args.orig) > 0) {
-    if(identical(args.orig[[1]][1], list(fun="affinity"))) {
+    if(identical(args.orig[[1]][1], list(fun = "affinity"))) {
       aargs <- args.orig[[1]]$args
       # We can only update arguments given after the first argument
       if(length(args.orig) > 1) {
@@ -49,7 +49,7 @@
 
   # The argument list
   args <- energy.args(args.orig, transect = transect)
-  args <- c(args, list(sout=sout, exceed.Ttr=exceed.Ttr, exceed.rhomin=exceed.rhomin))
+  args <- c(args, list(sout = sout, exceed.Ttr = exceed.Ttr, exceed.rhomin = exceed.rhomin))
 
   # The species we're given
   thermo <- get("thermo", CHNOSZ)
@@ -77,7 +77,7 @@
       # Add protein residues to the species list
       resnames <- c("H2O",aminoacids(3))
       # Residue activities set to zero; account for protein activities later
-      resprot <- paste(resnames,"RESIDUE",sep="_")
+      resprot <- paste(resnames,"RESIDUE",sep = "_")
       species(resprot, 0)
       thermo <- get("thermo", CHNOSZ)
       ires <- match(resprot, thermo$species$name)
@@ -93,7 +93,7 @@
       buffer <- TRUE
       message('affinity: loading buffer species')
       if(!is.null(thermo$species)) is.species <- 1:nrow(thermo$species) else is.species <- numeric()
-      is.buffer <- buffer(logK=NULL)
+      is.buffer <- buffer(logK = NULL)
       thermo <- get("thermo", CHNOSZ)
       is.buff <- numeric()
       for(i in 1:length(is.buffer)) is.buff <- c(is.buff,as.numeric(is.buffer[[i]]))
@@ -117,7 +117,7 @@
       logact.basis.new <- logact.basis <- do.call("energy",args)$a
       ibasis.new <- numeric()
       for(k in 1:length(buffers)) {
-        ibasis <- which(as.character(mybasis$logact)==buffers[k])
+        ibasis <- which(as.character(mybasis$logact) == buffers[k])
         # Calculate the logKs from the affinities
         logK <- a
         for(i in 1:length(logK)) {
@@ -126,8 +126,8 @@
             logK[[i]] <- logK[[i]] - logact.basis.new[[j]] * thermo$species[i,j]
           }
         }
-        lbn <- buffer(logK=logK,ibasis=ibasis,logact.basis=logact.basis.new,
-          is.buffer=as.numeric(is.buffer[[which(names(is.buffer)==buffers[k])]]),balance=balance)
+        lbn <- buffer(logK = logK,ibasis = ibasis,logact.basis = logact.basis.new,
+          is.buffer = as.numeric(is.buffer[[which(names(is.buffer) == buffers[k])]]),balance = balance)
         for(j in 1:length(logact.basis.new)) if(j %in% ibasis) logact.basis.new[[j]] <- lbn[[2]][[j]]
         # Calculation of the buffered activities' effect on chemical affinities
         is.only.buffer.new <- is.only.buffer[is.only.buffer %in% is.buffer[[k]]]
@@ -143,12 +143,12 @@
             #if(!identical(a[[i]],aa)) print(paste(i,j))
           }
         }
-        if(k==length(buffers) & return.buffer) {
+        if(k == length(buffers) & return.buffer) {
           logact.basis.new <- lbn[[2]]
           ibasis.new <- c(ibasis.new,lbn[[1]])
         } else ibasis.new <- c(ibasis.new,ibasis)
       }
-      species(is.only.buffer,delete=TRUE)
+      species(is.only.buffer,delete = TRUE)
       if(length(is.only.buffer) > 0) a <- a[-is.only.buffer]
       # To return the activities of buffered basis species
       tb <- logact.basis.new[unique(ibasis.new)]
@@ -159,9 +159,9 @@
           for(i in 1:length(tb)) {
             #tb[[i]] <- as.data.frame(tb[[i]])
             if(nd > 0) rownames(tb[[i]]) <- 
-              seq(args$lims[[1]][1],args$lims[[1]][2],length.out=args$lims[[1]][3])
+              seq(args$lims[[1]][1],args$lims[[1]][2],length.out = args$lims[[1]][3])
             if(nd > 1) colnames(tb[[i]]) <- 
-              seq(args$lims[[2]][1],args$lims[[2]][2],length.out=args$lims[[2]][3])
+              seq(args$lims[[2]][1],args$lims[[2]][2],length.out = args$lims[[2]][3])
           }
         }
       }
@@ -171,7 +171,7 @@
     if(!is.null(iprotein)) {
       # Fast protein calculations 20090331
       # Function to calculate affinity of formation reactions from those of residues
-      loga.protein <- rep(loga.protein,length.out=length(iprotein))
+      loga.protein <- rep(loga.protein,length.out = length(iprotein))
       protein.fun <- function(ip) {
         tpext <- as.numeric(thermo$protein[iprotein[ip],5:25])
         return(Reduce("+", pprod(a[ires],tpext)) - loga.protein[ip])
@@ -186,14 +186,14 @@
       # The current species list, containing the residues
       resspecies <- thermo$species
       # Now we can delete the residues from the species list
-      species(ires,delete=TRUE)
+      species(ires,delete = TRUE)
       # State and protein names
       state <- resspecies$state[1]
-      name <- paste(thermo$protein$protein[iprotein],thermo$protein$organism[iprotein],sep="_")
+      name <- paste(thermo$protein$protein[iprotein],thermo$protein$organism[iprotein],sep = "_")
       # The numbers of basis species in formation reactions of the proteins
       protbasis <- t(t((resspecies[ires,1:nrow(mybasis)])) %*% t((thermo$protein[iprotein,5:25])))
       # Put them together
-      protspecies <- cbind(protbasis,data.frame(ispecies=ispecies,logact=loga.protein,state=state,name=name))
+      protspecies <- cbind(protbasis,data.frame(ispecies = ispecies,logact = loga.protein,state = state,name = name))
       myspecies <- rbind(myspecies,protspecies)
       rownames(myspecies) <- 1:nrow(myspecies)
       ## Update the affinity values
@@ -231,8 +231,8 @@
     # they got converted to log_a(e-) at an unknown temperature
     Eharg <- args.orig[[iEh]]
     if(length(Eharg) > 3) Ehvals <- Eharg
-    else if(length(Eharg) == 3) Ehvals <- seq(Eharg[1], Eharg[2], length.out=Eharg[3])
-    else if(length(Eharg) == 2) Ehvals <- seq(Eharg[1], Eharg[2], length.out=256)
+    else if(length(Eharg) == 3) Ehvals <- seq(Eharg[1], Eharg[2], length.out = Eharg[3])
+    else if(length(Eharg) == 2) Ehvals <- seq(Eharg[1], Eharg[2], length.out = 256)
     vals[[iEh]] <- Ehvals
   }
   # Get pe and pH
@@ -252,18 +252,18 @@
   names(vals) <- vars
 
   # Content of return value depends on buffer request
-  if(return.buffer) return(c(tb, list(vars=vars, vals=vals)))
+  if(return.buffer) return(c(tb, list(vars = vars, vals = vals)))
   # For argument recall, include all arguments (except sout) in output 20190117
-  allargs <- c(args.orig, list(property=property, exceed.Ttr=exceed.Ttr, exceed.rhomin=exceed.rhomin,
-    return.buffer=return.buffer, balance=balance, iprotein=iprotein, loga.protein=loga.protein))
+  allargs <- c(args.orig, list(property = property, exceed.Ttr = exceed.Ttr, exceed.rhomin = exceed.rhomin,
+    return.buffer = return.buffer, balance = balance, iprotein = iprotein, loga.protein = loga.protein))
   # Add IS value only if it given as an argument 20171101
   # (even if its value is 0, the presence of IS will trigger diagram() to use "m" instead of "a" in axis labels)
   iIS <- match("IS", names(args.orig))
-  if(!is.na(iIS)) a <- list(fun="affinity", args=allargs, sout=sout, property=property,
-                            basis=mybasis, species=myspecies, T=T, P=P, IS=args$IS, vars=vars, vals=vals, values=a)
-  else a <- list(fun="affinity", args=allargs, sout=sout, property=property,
-                 basis=mybasis, species=myspecies, T=T, P=P, vars=vars, vals=vals, values=a)
-  if(buffer) a <- c(a, list(buffer=tb))
+  if(!is.na(iIS)) a <- list(fun = "affinity", args = allargs, sout = sout, property = property,
+                            basis = mybasis, species = myspecies, T = T, P = P, IS = args$IS, vars = vars, vals = vals, values = a)
+  else a <- list(fun = "affinity", args = allargs, sout = sout, property = property,
+                 basis = mybasis, species = myspecies, T = T, P = P, vars = vars, vals = vals, values = a)
+  if(buffer) a <- c(a, list(buffer = tb))
   return(a)
 }
 

Modified: pkg/CHNOSZ/R/basis.R
===================================================================
--- pkg/CHNOSZ/R/basis.R	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/R/basis.R	2023-06-24 00:59:45 UTC (rev 793)
@@ -137,7 +137,7 @@
   newbasis
 }
 
-### unexported functions ###
+### Unexported functions ###
 
 # To add the basis to thermo()$OBIGT
 put.basis <- function(ispecies, logact = rep(NA, length(ispecies))) {
@@ -146,17 +146,17 @@
   # Make the basis matrix, revised 20120114
   # Get the elemental makeup of each species,
   # counting zero for any element that only appears in other species in the set
-  comp <- makeup(ispecies, count.zero=TRUE)
+  comp <- makeup(ispecies, count.zero = TRUE)
   # Turn the list into a matrix
   comp <- sapply(comp, c)
   # Transpose to get put basis species on the rows
   comp <- t(comp)
-  # Note, makeup(count.zero=TRUE) above gave elements (colnames) sorted alphabetically
+  # Note, makeup(count.zero = TRUE) above gave elements (colnames) sorted alphabetically
   # rownames identify the species
   rownames(comp) <- as.character(thermo$OBIGT$formula[ispecies])
   # FIXME: the electron doesn't look like a chemical formula
   # This is needed for affinity() to understand a 'pe' or 'Eh' variable
-  if("(Z-1)" %in% rownames(comp)) rownames(comp)[rownames(comp)=="(Z-1)"] <- "e-"
+  if("(Z-1)" %in% rownames(comp)) rownames(comp)[rownames(comp) == "(Z-1)"] <- "e-"
   # Now check it for validity of basis species
   # The first test: matrix is square
   if( nrow(comp) > ncol(comp) ) {
@@ -172,7 +172,7 @@
     stop("singular stoichiometric matrix")
   # Store the basis definition in thermo()$basis, including
   # both numeric and character data, so we need to use a data frame
-  comp <- cbind(as.data.frame(comp), ispecies, logact, state, stringsAsFactors=FALSE)
+  comp <- cbind(as.data.frame(comp), ispecies, logact, state, stringsAsFactors = FALSE)
   # Ready to assign to the global thermo object
   thermo$basis <- comp
   assign("thermo", thermo, CHNOSZ)
@@ -179,7 +179,7 @@
 }
 
 # Modify the states or logact values in the existing basis definition
-mod.basis <- function(species, state=NULL, logact=NULL) {
+mod.basis <- function(species, state = NULL, logact = NULL) {
   thermo <- get("thermo", CHNOSZ)
   # The basis must be defined
   if(is.null(thermo$basis)) stop("basis is not defined")
@@ -197,7 +197,7 @@
     if(!is.null(state)) {
       if(state[i] %in% thermo$buffer$name) {
         # This is the name of a buffer
-        ibuff <- which(as.character(thermo$buffer$name)==state[i])
+        ibuff <- which(as.character(thermo$buffer$name) == state[i])
         # Check that each species in the buffer is compositionally compatible with the basis definition
         for(k in 1:length(ibuff)) {
           ispecies <- suppressMessages(info(as.character(thermo$buffer$species)[ibuff[k]],
@@ -207,7 +207,7 @@
           if(FALSE %in% inbasis) {
             stop(paste("the elements '",c2s(names(bufmakeup)[!inbasis]),
               "' of species '",thermo$buffer$species[ibuff[k]],"' in buffer '",state[i],
-              "' are not in the basis\n",sep=""))
+              "' are not in the basis\n",sep = ""))
           }
         }
         thermo$basis$logact[ib] <- state[i]
@@ -221,7 +221,7 @@
           ispecies <- suppressMessages(info(myformula, state[i]))
           if(is.na(ispecies) | is.list(ispecies)) {
             # If that failed, we're out of luck
-            if(myname==myformula) nametxt <- myname else nametxt <- paste(myname, "or", myformula)
+            if(myname == myformula) nametxt <- myname else nametxt <- paste(myname, "or", myformula)
             stop(paste0("state or buffer '", state[i], "' not found for ", nametxt, "\n"))
           }
         }
@@ -242,7 +242,7 @@
 } 
 
 # To load a preset basis definition by keyword
-preset.basis <- function(key=NULL) {
+preset.basis <- function(key = NULL) {
   # The available keywords
   basis.key <- c("CHNOS", "CHNOS+", "CHNOSe", "CHNOPS+", "CHNOPSe", "MgCHNOPS+", "MgCHNOPSe", "FeCHNOS", "FeCHNOS+", "QEC4", "QEC", "QEC+", "QCa", "QCa+")
   # Just list the keywords if none is specified
@@ -252,23 +252,23 @@
   # Match the keyword to the available ones
   ibase <- match(key, basis.key)
   if(is.na(ibase)) stop(paste(key, "is not a keyword for preset basis species"))
-  if(ibase==1) species <- c("CO2", "H2O", "NH3", "H2S", "oxygen")
-  else if(ibase==2) species <- c("CO2", "H2O", "NH3", "H2S", "oxygen", "H+")
-  else if(ibase==3) species <- c("CO2", "H2O", "NH3", "H2S", "e-", "H+")
-  else if(ibase==4) species <- c("CO2", "H2O", "NH3", "H3PO4", "H2S", "oxygen", "H+")
-  else if(ibase==5) species <- c("CO2", "H2O", "NH3", "H3PO4", "H2S", "e-", "H+")
-  else if(ibase==6) species <- c("Mg+2", "CO2", "H2O", "NH3", "H3PO4", "H2S", "oxygen", "H+")
-  else if(ibase==7) species <- c("Mg+2", "CO2", "H2O", "NH3", "H3PO4", "H2S", "e-", "H+")
-  else if(ibase==8) species <- c("Fe2O3", "CO2", "H2O", "NH3", "H2S", "oxygen")
-  else if(ibase==9) species <- c("Fe2O3", "CO2", "H2O", "NH3", "H2S", "oxygen", "H+")
+  if(ibase == 1) species <- c("CO2", "H2O", "NH3", "H2S", "oxygen")
+  else if(ibase == 2) species <- c("CO2", "H2O", "NH3", "H2S", "oxygen", "H+")
+  else if(ibase == 3) species <- c("CO2", "H2O", "NH3", "H2S", "e-", "H+")
+  else if(ibase == 4) species <- c("CO2", "H2O", "NH3", "H3PO4", "H2S", "oxygen", "H+")
+  else if(ibase == 5) species <- c("CO2", "H2O", "NH3", "H3PO4", "H2S", "e-", "H+")
+  else if(ibase == 6) species <- c("Mg+2", "CO2", "H2O", "NH3", "H3PO4", "H2S", "oxygen", "H+")
+  else if(ibase == 7) species <- c("Mg+2", "CO2", "H2O", "NH3", "H3PO4", "H2S", "e-", "H+")
+  else if(ibase == 8) species <- c("Fe2O3", "CO2", "H2O", "NH3", "H2S", "oxygen")
+  else if(ibase == 9) species <- c("Fe2O3", "CO2", "H2O", "NH3", "H2S", "oxygen", "H+")
   else if(ibase %in% c(10, 11)) species <- c("glutamine", "glutamic acid", "cysteine", "H2O", "oxygen")
-  else if(ibase==12) species <- c("glutamine", "glutamic acid", "cysteine", "H2O", "oxygen", "H+")
-  else if(ibase==13) species <- c("glutamine", "cysteine", "acetic acid", "H2O", "oxygen")
-  else if(ibase==14) species <- c("glutamine", "cysteine", "acetic acid", "H2O", "oxygen", "H+")
+  else if(ibase == 12) species <- c("glutamine", "glutamic acid", "cysteine", "H2O", "oxygen", "H+")
+  else if(ibase == 13) species <- c("glutamine", "cysteine", "acetic acid", "H2O", "oxygen")
+  else if(ibase == 14) species <- c("glutamine", "cysteine", "acetic acid", "H2O", "oxygen", "H+")
   # Get the preset logact
   logact <- preset.logact(species)
   # For QEC4, we use logact = -4 for the amino acids
-  if(key=="QEC4") logact[1:3] <- -4
+  if(key == "QEC4") logact[1:3] <- -4
   # Load the species and return the result
   return(basis(species, logact))
 }

Modified: pkg/CHNOSZ/R/buffer.R
===================================================================
--- pkg/CHNOSZ/R/buffer.R	2023-06-23 14:00:30 UTC (rev 792)
+++ pkg/CHNOSZ/R/buffer.R	2023-06-24 00:59:45 UTC (rev 793)
@@ -6,7 +6,7 @@
   # 20071102 add or change a buffer system
   thermo <- get("thermo", CHNOSZ)
   if(is.null(species)) {
-    iname <- which(name==thermo$buffer$name)
+    iname <- which(name == thermo$buffer$name)
     if(length(iname)>0) species <- thermo$buffer$species[iname]
     else species <- character()
   }
@@ -13,22 +13,22 @@
   ls <- length(species)
   if(ls < length(name) | ls < length(state) | ls < length(logact))
     stop('species must be at least as long as the other arguments')
-  if(length(name)!=ls) name <- rep(name,length.out=ls)
+  if(length(name) != ls) name <- rep(name,length.out = ls)
   add <- TRUE
   if(TRUE %in% (name %in% thermo$buffer$name)) {
     add <- FALSE
     imod <- which(thermo$buffer$name %in% name & thermo$buffer$species %in% species)
     if(length(imod)>0) {
-      if(state[1]=='') {
+      if(state[1] == '') {
         thermo$buffer <- thermo$buffer[-imod,]
         assign("thermo", thermo, CHNOSZ)
         message(paste('mod.buffer: removed ',c2s(species),' in ',
-          c2s(unique(name)),' buffer',sep=''))
+          c2s(unique(name)),' buffer',sep = ''))
       } else {
         if(missing(state)) state <- thermo$buffer$state[imod]
         if(missing(logact)) logact <- thermo$buffer$logact[imod]
-        if(length(state)!=ls) state <- rep(state,length.out=ls)
-        if(length(logact)!=ls) logact <- rep(logact,length.out=ls)
+        if(length(state) != ls) state <- rep(state,length.out = ls)
+        if(length(logact) != ls) logact <- rep(logact,length.out = ls)
         state.old <- thermo$buffer$state[imod]
         logact.old <- thermo$buffer$logact[imod]
         thermo$buffer$state[imod] <- state
@@ -36,10 +36,10 @@
         assign("thermo", thermo, CHNOSZ)
         if(identical(state.old,state) & identical(logact.old,logact)) {
           message(paste('mod.buffer: nothing changed for ',
-            c2s(species),' in ',c2s(unique(name)),' buffer',sep=''))
+            c2s(species),' in ',c2s(unique(name)),' buffer',sep = ''))
         } else {
           message(paste('mod.buffer: changed state and/or logact of ',
-            c2s(species),' in ',c2s(unique(name)),' buffer',sep=''))
+            c2s(species),' in ',c2s(unique(name)),' buffer',sep = ''))
         }
       }
     } else {
@@ -47,8 +47,8 @@
     }
   } 
   if(add) {
-    if(state[1]=='') state <- rep(thermo$opt$state,length.out=ls)
-    t <- data.frame(name=name,species=species,state=state,logact=logact)
+    if(state[1] == '') state <- rep(thermo$opt$state,length.out = ls)
+    t <- data.frame(name = name,species = species,state = state,logact = logact)
     thermo$buffer <- rbind(thermo$buffer,t)
     assign("thermo", thermo, CHNOSZ)
     message(paste('mod.buffer: added',c2s(unique(name))))
@@ -58,7 +58,7 @@
 
 ### Unexported functions ###
 
-buffer <- function(logK=NULL,ibasis=NULL,logact.basis=NULL,is.buffer=NULL,balance='PBB') {
+buffer <- function(logK = NULL,ibasis = NULL,logact.basis = NULL,is.buffer = NULL,balance = 'PBB') {
   thermo <- get("thermo", CHNOSZ)
   # If logK is NULL load the buffer species,
   # otherwise perform buffer calculations
@@ -67,14 +67,14 @@
     buffers <- unique(as.character(thermo$basis$logact)[!can.be.numeric(as.character(thermo$basis$logact))])
     ispecies.new <- list()
     for(k in 1:length(buffers)) {
-      ibasis <- which(thermo$basis$logact==buffers[k])
+      ibasis <- which(thermo$basis$logact == buffers[k])
       ispecies <- numeric()
       for(i in 1:length(ibasis)) {
-        ib <- as.character(thermo$buffer$name)==as.character(thermo$basis$logact[ibasis[i]])
+        ib <- as.character(thermo$buffer$name) == as.character(thermo$basis$logact[ibasis[i]])
         species <- as.character(thermo$buffer$species)[ib]
         state <- as.character(thermo$buffer$state)[ib]
-        #ibuff <- info(species,state,quiet=TRUE)
-        ispecies <- c(ispecies, species(species, state, index.return=TRUE, add = TRUE))
+        #ibuff <- info(species,state,quiet = TRUE)
+        ispecies <- c(ispecies, species(species, state, index.return = TRUE, add = TRUE))
       }
       ispecies.new <- c(ispecies.new,list(ispecies))
       # Make sure to set the activities
@@ -92,16 +92,16 @@
   bufname <- thermo$basis$logact[ibasis[1]]
   basisnames <- rownames(thermo$basis)
   are.proteins <- grep('_',as.character(thermo$species$name[is.buffer]))
-  if((length(are.proteins)>0 & balance=='PBB') | balance==1) {
-    if(balance==1) {
+  if((length(are.proteins)>0 & balance == 'PBB') | balance == 1) {
+    if(balance == 1) {
       basisnames <- c('product',basisnames)
       nb <- rep(1,nrow(bufbasis))
-      bufbasis <- cbind(data.frame(product=nb),bufbasis)
+      bufbasis <- cbind(data.frame(product = nb),bufbasis)
     } else {
       basisnames <- c('PBB',basisnames)
       # Prepend a PBB column to bufbasis and increment ibasis by 1
       nb <- as.numeric(protein.length(thermo$species$name[is.buffer]))
-      bufbasis <- cbind(data.frame(PBB=nb),bufbasis)
+      bufbasis <- cbind(data.frame(PBB = nb),bufbasis)
     }
     ibasis <- ibasis + 1
     # Make logact.basis long enough
@@ -112,7 +112,7 @@
     logact.basis <- logact.basis[ilb]
   }
   # Say hello
-  #message(paste("buffer: '",bufname,"', of ",length(is.buffer),' species, ',length(ibasis),' activity(s) requested.',sep=''))
+  #message(paste("buffer: '",bufname,"', of ",length(is.buffer),' species, ',length(ibasis),' activity(s) requested.',sep = ''))
   ibasisrequested <- ibasis
   # Check and maybe add to the number of buffered activities
   ibasisadded <- numeric()
@@ -125,7 +125,7 @@
       # look for additional activities to buffer ... do columns in reverse 
       for(j in ncol(bufbasis):1) {
         if(j %in% ibasis) next
-        if(FALSE %in% (bufbasis[,j]==0)) {
+        if(FALSE %in% (bufbasis[,j] == 0)) {
           newbasis <- j
           break
         }
@@ -134,7 +134,7 @@
         ibasis <- c(ibasis,newbasis)
         ibasisadded <- c(ibasisadded,newbasis)
       } else {
-        stop('can not find enough buffered basis species for ',thermo$basis$logact[ibasis[1]],'.',sep='')
+        stop('can not find enough buffered basis species for ',thermo$basis$logact[ibasis[1]],'.',sep = '')
       }
     }
   } 
@@ -146,28 +146,28 @@
     # First try to get one that is present in all species
     for(i in ncol(bufbasis):1) {
       if(i %in% ibasis) next
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/chnosz -r 793


More information about the CHNOSZ-commits mailing list