Running 'testthat.R'
Running the tests in 'tests/testthat.R' failed.
Complete output:
  > library(testthat)
  > library(CHNOSZ)
  CHNOSZ version 1.4.1 (2021-04-08)
  reset: creating "thermo" object
  OBIGT: loading default database with 1903 aqueous, 3443 total species
  > 
  > # as fix for https://github.com/hadley/testthat/issues/129, https://github.com/hadley/testthat/issues/144
  > # (since we use makeCluster() etc via palply)
  > Sys.setenv("R_TESTS" = "") 
  > 
  > test_check("CHNOSZ")
  [ FAIL 9 | WARN 0 | SKIP 0 | PASS 591 ]
  
  ══ Failed tests ════════════════════════════════════════════════════════════════
  ── Error (test-mix.R:61:3): mix() and mosaic() yield same affinities for a bimetallic mineral ──
  Error in `mosaic(list(Fe, Cu), pH = pH, Eh = Eh, T = 300, blend = FALSE)`: the starting basis does not have iron and copper
  Backtrace:
      ▆
   1. └─CHNOSZ::mosaic(list(Fe, Cu), pH = pH, Eh = Eh, T = 300, blend = FALSE) at test-mix.R:61:2
  ── Error (test-mosaic.R:12:3): results are consistent with affinity() ──────────
  Error in `mosaic(list("NH3", "CO2"))`: the starting basis does not have NH3 and CO2
  Backtrace:
      ▆
   1. └─CHNOSZ::mosaic(list("NH3", "CO2")) at test-mosaic.R:12:2
  ── Error (test-mosaic.R:40:3): blend=TRUE produces reasonable values ───────────
  Error in `(function (bases, blend = TRUE, stable = list(), ...) 
  {
      if (is.list(bases)) {
          if (identical(bases[1], list(fun = "mosaic"))) {
              aargs <- bases$args
              ddd <- list(...)
              if (length(ddd) > 0) {
                  for (i in 1:length(ddd)) {
                    if (names(ddd)[i] %in% names(aargs)) 
                      aargs[[names(ddd)[i]]] <- ddd[[i]]
                    else aargs <- c(aargs, ddd[i])
                  }
              }
              return(do.call(mosaic, aargs))
          }
      }
      if (!is.list(bases)) {
          bases <- list(bases)
          otherargs <- list(...)
          allargs <- c(list(bases = bases, blend = blend, stable = stable), 
              otherargs)
          out <- do.call(mosaic, allargs)
          out$A.bases <- out$A.bases[[1]]
          return(out)
      }
      basis0 <- get("thermo", CHNOSZ)$basis
      species0 <- get("thermo", CHNOSZ)$species
      ispecies <- lapply(bases, info)
      if (any(is.na(unlist(ispecies)))) 
          stop("one or more of the requested basis species is unavailable")
      ispecies0 <- sapply(ispecies, "[", 1)
      ibasis0 <- match(ispecies0, basis0$ispecies)
      ina <- is.na(ibasis0)
      if (any(ina)) {
          names0 <- unlist(lapply(bases, "[", 1))
          stop("the starting basis does not have ", paste(names0[ina], 
              collapse = " and "))
      }
      ddd <- list(...)
      if ("sout" %in% names(ddd)) {
          ddd_has_sout <- TRUE
          sout <- ddd$sout
      }
      else {
          ddd_has_sout <- FALSE
          lapply(bases, species, add = TRUE)
          sout <- affinity(..., return.sout = TRUE)
      }
      A.bases <- list()
      for (i in 1:length(bases)) {
          message("mosaic: calculating affinities of basis species group ", 
              i, ": ", paste(bases[[i]], collapse = " "))
          mysp <- species(bases[[i]])
          iaq <- mysp$state == "aq"
          if (any(iaq)) 
              species(which(iaq), as.numeric(basis0$logact[ibasis0[i]]))
          if (ddd_has_sout) 
              A.bases[[i]] <- suppressMessages(affinity(...))
          else A.bases[[i]] <- suppressMessages(affinity(..., sout = sout))
      }
      newbases <- as.matrix(expand.grid(ispecies))
      allbases <- matrix(basis0$ispecies, nrow = 1)[rep(1, nrow(newbases)), 
          , drop = FALSE]
      allbases[, ibasis0] <- newbases
      aff.species <- list()
      message("mosaic: calculating affinities of species for all ", 
          nrow(allbases), " combinations of the basis species")
      for (i in nrow(allbases):1) {
          thislogact <- basis0$logact
          states <- sout$species$state[match(allbases[i, ], sout$species$ispecies)]
          icr <- grepl("cr", states)
          thislogact[icr] <- 0
          put.basis(allbases[i, ], thislogact)
          species(species0$ispecies, species0$logact)
          if (ddd_has_sout) 
              aff.species[[i]] <- suppressMessages(affinity(...))
          else aff.species[[i]] <- suppressMessages(affinity(..., 
              sout = sout))
      }
      group.fraction <- list()
      blend <- rep(blend, length(A.bases))
      E.bases <- list()
      for (i in 1:length(A.bases)) {
          if (blend[i] & is.null(stable[i][[1]])) {
              if (any(!sapply(A.bases[[1]]$values, is.na))) {
                  e <- equilibrate(A.bases[[i]], loga.balance = as.numeric(basis0$logact[ibasis0[i]]))
                  a.equil <- lapply(e$loga.equil, function(x) 10^x)
                  a.tot <- Reduce("+", a.equil)
                  group.fraction[[i]] <- lapply(a.equil, function(x) x/a.tot)
                  E.bases[[i]] <- e
              }
              else {
                  group.fraction[[i]] <- A.bases[[i]]$values
              }
          }
          else {
              if (is.null(stable[i][[1]])) {
                  d <- diagram(A.bases[[i]], plot.it = FALSE, limit.water = FALSE)
                  predom <- d$predominant
              }
              else {
                  predom <- stable[i][[1]]
              }
              group.fraction[[i]] <- list()
              for (j in 1:length(bases[[i]])) {
                  yesno <- predom
                  yesno[yesno != j] <- 0
                  yesno[yesno == j] <- 1
                  group.fraction[[i]][[j]] <- yesno
              }
          }
      }
      ind.mat <- list()
      for (i in 1:length(ispecies)) ind.mat[[i]] <- 1:length(ispecies[[i]])
      ind.mat <- as.matrix(expand.grid(ind.mat))
      for (icomb in 1:nrow(ind.mat)) {
          for (igroup in 1:ncol(ind.mat)) {
              basisx <- group.fraction[[igroup]][[ind.mat[icomb, 
                  igroup]]]
              for (jspecies in 1:length(aff.species[[icomb]]$values)) {
                  nbasis <- aff.species[[icomb]]$species[jspecies, 
                    ibasis0[igroup]]
                  aff.adjust <- nbasis * log10(basisx)
                  isfin <- is.finite(aff.adjust)
                  aff.species[[icomb]]$values[[jspecies]][isfin] <- aff.species[[icomb]]$values[[jspecies]][isfin] + 
                    aff.adjust[isfin]
              }
              if (igroup == 1) 
                  groupx <- basisx
              else groupx <- groupx * basisx
          }
          aff.species[[icomb]]$values <- lapply(aff.species[[icomb]]$values, 
              function(values) values * groupx)
      }
      A.species <- aff.species[[1]]
      for (i in 1:length(A.species$values)) {
          A.values <- lapply(lapply(aff.species, "[[", "values"), 
              "[[", i)
          A.species$values[[i]] <- Reduce("+", A.values)
      }
      allargs <- c(list(bases = bases, blend = blend), list(...))
      return(list(fun = "mosaic", args = allargs, A.species = A.species, 
          A.bases = A.bases, E.bases = E.bases))
  })(bases = list(c("SO4-2", "HSO4-", "HS-", "H2S")), blend = FALSE, 
      stable = list(), pH = c(0, 14, 29))`: the starting basis does not have SO4-2
  Backtrace:
      ▆
   1. └─CHNOSZ::mosaic(bases, pH = pH, blend = FALSE) at test-mosaic.R:40:2
   2.   ├─base::do.call(mosaic, allargs)
   3.   └─CHNOSZ `<fn>`(bases = `<list>`, blend = FALSE, stable = `<list>`, pH = `<dbl>`)
  ── Error (test-mosaic.R:60:3): mosaic() - equilibrate() produces equilibrium activities ──
  Error in `(function (bases, blend = TRUE, stable = list(), ...) 
  {
      if (is.list(bases)) {
          if (identical(bases[1], list(fun = "mosaic"))) {
              aargs <- bases$args
              ddd <- list(...)
              if (length(ddd) > 0) {
                  for (i in 1:length(ddd)) {
                    if (names(ddd)[i] %in% names(aargs)) 
                      aargs[[names(ddd)[i]]] <- ddd[[i]]
                    else aargs <- c(aargs, ddd[i])
                  }
              }
              return(do.call(mosaic, aargs))
          }
      }
      if (!is.list(bases)) {
          bases <- list(bases)
          otherargs <- list(...)
          allargs <- c(list(bases = bases, blend = blend, stable = stable), 
              otherargs)
          out <- do.call(mosaic, allargs)
          out$A.bases <- out$A.bases[[1]]
          return(out)
      }
      basis0 <- get("thermo", CHNOSZ)$basis
      species0 <- get("thermo", CHNOSZ)$species
      ispecies <- lapply(bases, info)
      if (any(is.na(unlist(ispecies)))) 
          stop("one or more of the requested basis species is unavailable")
      ispecies0 <- sapply(ispecies, "[", 1)
      ibasis0 <- match(ispecies0, basis0$ispecies)
      ina <- is.na(ibasis0)
      if (any(ina)) {
          names0 <- unlist(lapply(bases, "[", 1))
          stop("the starting basis does not have ", paste(names0[ina], 
              collapse = " and "))
      }
      ddd <- list(...)
      if ("sout" %in% names(ddd)) {
          ddd_has_sout <- TRUE
          sout <- ddd$sout
      }
      else {
          ddd_has_sout <- FALSE
          lapply(bases, species, add = TRUE)
          sout <- affinity(..., return.sout = TRUE)
      }
      A.bases <- list()
      for (i in 1:length(bases)) {
          message("mosaic: calculating affinities of basis species group ", 
              i, ": ", paste(bases[[i]], collapse = " "))
          mysp <- species(bases[[i]])
          iaq <- mysp$state == "aq"
          if (any(iaq)) 
              species(which(iaq), as.numeric(basis0$logact[ibasis0[i]]))
          if (ddd_has_sout) 
              A.bases[[i]] <- suppressMessages(affinity(...))
          else A.bases[[i]] <- suppressMessages(affinity(..., sout = sout))
      }
      newbases <- as.matrix(expand.grid(ispecies))
      allbases <- matrix(basis0$ispecies, nrow = 1)[rep(1, nrow(newbases)), 
          , drop = FALSE]
      allbases[, ibasis0] <- newbases
      aff.species <- list()
      message("mosaic: calculating affinities of species for all ", 
          nrow(allbases), " combinations of the basis species")
      for (i in nrow(allbases):1) {
          thislogact <- basis0$logact
          states <- sout$species$state[match(allbases[i, ], sout$species$ispecies)]
          icr <- grepl("cr", states)
          thislogact[icr] <- 0
          put.basis(allbases[i, ], thislogact)
          species(species0$ispecies, species0$logact)
          if (ddd_has_sout) 
              aff.species[[i]] <- suppressMessages(affinity(...))
          else aff.species[[i]] <- suppressMessages(affinity(..., 
              sout = sout))
      }
      group.fraction <- list()
      blend <- rep(blend, length(A.bases))
      E.bases <- list()
      for (i in 1:length(A.bases)) {
          if (blend[i] & is.null(stable[i][[1]])) {
              if (any(!sapply(A.bases[[1]]$values, is.na))) {
                  e <- equilibrate(A.bases[[i]], loga.balance = as.numeric(basis0$logact[ibasis0[i]]))
                  a.equil <- lapply(e$loga.equil, function(x) 10^x)
                  a.tot <- Reduce("+", a.equil)
                  group.fraction[[i]] <- lapply(a.equil, function(x) x/a.tot)
                  E.bases[[i]] <- e
              }
              else {
                  group.fraction[[i]] <- A.bases[[i]]$values
              }
          }
          else {
              if (is.null(stable[i][[1]])) {
                  d <- diagram(A.bases[[i]], plot.it = FALSE, limit.water = FALSE)
                  predom <- d$predominant
              }
              else {
                  predom <- stable[i][[1]]
              }
              group.fraction[[i]] <- list()
              for (j in 1:length(bases[[i]])) {
                  yesno <- predom
                  yesno[yesno != j] <- 0
                  yesno[yesno == j] <- 1
                  group.fraction[[i]][[j]] <- yesno
              }
          }
      }
      ind.mat <- list()
      for (i in 1:length(ispecies)) ind.mat[[i]] <- 1:length(ispecies[[i]])
      ind.mat <- as.matrix(expand.grid(ind.mat))
      for (icomb in 1:nrow(ind.mat)) {
          for (igroup in 1:ncol(ind.mat)) {
              basisx <- group.fraction[[igroup]][[ind.mat[icomb, 
                  igroup]]]
              for (jspecies in 1:length(aff.species[[icomb]]$values)) {
                  nbasis <- aff.species[[icomb]]$species[jspecies, 
                    ibasis0[igroup]]
                  aff.adjust <- nbasis * log10(basisx)
                  isfin <- is.finite(aff.adjust)
                  aff.species[[icomb]]$values[[jspecies]][isfin] <- aff.species[[icomb]]$values[[jspecies]][isfin] + 
                    aff.adjust[isfin]
              }
              if (igroup == 1) 
                  groupx <- basisx
              else groupx <- groupx * basisx
          }
          aff.species[[icomb]]$values <- lapply(aff.species[[icomb]]$values, 
              function(values) values * groupx)
      }
      A.species <- aff.species[[1]]
      for (i in 1:length(A.species$values)) {
          A.values <- lapply(lapply(aff.species, "[[", "values"), 
              "[[", i)
          A.species$values[[i]] <- Reduce("+", A.values)
      }
      allargs <- c(list(bases = bases, blend = blend), list(...))
      return(list(fun = "mosaic", args = allargs, A.species = A.species, 
          A.bases = A.bases, E.bases = E.bases))
  })(bases = list(c("NH3", "NH4+")), blend = TRUE, stable = list(), 
      pH = c(0, 14))`: the starting basis does not have NH3
  Backtrace:
      ▆
   1. └─CHNOSZ::mosaic(c("NH3", "NH4+"), pH = c(0, 14)) at test-mosaic.R:60:2
   2.   ├─base::do.call(mosaic, allargs)
   3.   └─CHNOSZ `<fn>`(bases = `<list>`, blend = TRUE, stable = `<list>`, pH = `<dbl>`)
  ── Error (test-mosaic.R:97:3): mosaic() - solubility() produces equilibrium activities ──
  Error in `(function (bases, blend = TRUE, stable = list(), ...) 
  {
      if (is.list(bases)) {
          if (identical(bases[1], list(fun = "mosaic"))) {
              aargs <- bases$args
              ddd <- list(...)
              if (length(ddd) > 0) {
                  for (i in 1:length(ddd)) {
                    if (names(ddd)[i] %in% names(aargs)) 
                      aargs[[names(ddd)[i]]] <- ddd[[i]]
                    else aargs <- c(aargs, ddd[i])
                  }
              }
              return(do.call(mosaic, aargs))
          }
      }
      if (!is.list(bases)) {
          bases <- list(bases)
          otherargs <- list(...)
          allargs <- c(list(bases = bases, blend = blend, stable = stable), 
              otherargs)
          out <- do.call(mosaic, allargs)
          out$A.bases <- out$A.bases[[1]]
          return(out)
      }
      basis0 <- get("thermo", CHNOSZ)$basis
      species0 <- get("thermo", CHNOSZ)$species
      ispecies <- lapply(bases, info)
      if (any(is.na(unlist(ispecies)))) 
          stop("one or more of the requested basis species is unavailable")
      ispecies0 <- sapply(ispecies, "[", 1)
      ibasis0 <- match(ispecies0, basis0$ispecies)
      ina <- is.na(ibasis0)
      if (any(ina)) {
          names0 <- unlist(lapply(bases, "[", 1))
          stop("the starting basis does not have ", paste(names0[ina], 
              collapse = " and "))
      }
      ddd <- list(...)
      if ("sout" %in% names(ddd)) {
          ddd_has_sout <- TRUE
          sout <- ddd$sout
      }
      else {
          ddd_has_sout <- FALSE
          lapply(bases, species, add = TRUE)
          sout <- affinity(..., return.sout = TRUE)
      }
      A.bases <- list()
      for (i in 1:length(bases)) {
          message("mosaic: calculating affinities of basis species group ", 
              i, ": ", paste(bases[[i]], collapse = " "))
          mysp <- species(bases[[i]])
          iaq <- mysp$state == "aq"
          if (any(iaq)) 
              species(which(iaq), as.numeric(basis0$logact[ibasis0[i]]))
          if (ddd_has_sout) 
              A.bases[[i]] <- suppressMessages(affinity(...))
          else A.bases[[i]] <- suppressMessages(affinity(..., sout = sout))
      }
      newbases <- as.matrix(expand.grid(ispecies))
      allbases <- matrix(basis0$ispecies, nrow = 1)[rep(1, nrow(newbases)), 
          , drop = FALSE]
      allbases[, ibasis0] <- newbases
      aff.species <- list()
      message("mosaic: calculating affinities of species for all ", 
          nrow(allbases), " combinations of the basis species")
      for (i in nrow(allbases):1) {
          thislogact <- basis0$logact
          states <- sout$species$state[match(allbases[i, ], sout$species$ispecies)]
          icr <- grepl("cr", states)
          thislogact[icr] <- 0
          put.basis(allbases[i, ], thislogact)
          species(species0$ispecies, species0$logact)
          if (ddd_has_sout) 
              aff.species[[i]] <- suppressMessages(affinity(...))
          else aff.species[[i]] <- suppressMessages(affinity(..., 
              sout = sout))
      }
      group.fraction <- list()
      blend <- rep(blend, length(A.bases))
      E.bases <- list()
      for (i in 1:length(A.bases)) {
          if (blend[i] & is.null(stable[i][[1]])) {
              if (any(!sapply(A.bases[[1]]$values, is.na))) {
                  e <- equilibrate(A.bases[[i]], loga.balance = as.numeric(basis0$logact[ibasis0[i]]))
                  a.equil <- lapply(e$loga.equil, function(x) 10^x)
                  a.tot <- Reduce("+", a.equil)
                  group.fraction[[i]] <- lapply(a.equil, function(x) x/a.tot)
                  E.bases[[i]] <- e
              }
              else {
                  group.fraction[[i]] <- A.bases[[i]]$values
              }
          }
          else {
              if (is.null(stable[i][[1]])) {
                  d <- diagram(A.bases[[i]], plot.it = FALSE, limit.water = FALSE)
                  predom <- d$predominant
              }
              else {
                  predom <- stable[i][[1]]
              }
              group.fraction[[i]] <- list()
              for (j in 1:length(bases[[i]])) {
                  yesno <- predom
                  yesno[yesno != j] <- 0
                  yesno[yesno == j] <- 1
                  group.fraction[[i]][[j]] <- yesno
              }
          }
      }
      ind.mat <- list()
      for (i in 1:length(ispecies)) ind.mat[[i]] <- 1:length(ispecies[[i]])
      ind.mat <- as.matrix(expand.grid(ind.mat))
      for (icomb in 1:nrow(ind.mat)) {
          for (igroup in 1:ncol(ind.mat)) {
              basisx <- group.fraction[[igroup]][[ind.mat[icomb, 
                  igroup]]]
              for (jspecies in 1:length(aff.species[[icomb]]$values)) {
                  nbasis <- aff.species[[icomb]]$species[jspecies, 
                    ibasis0[igroup]]
                  aff.adjust <- nbasis * log10(basisx)
                  isfin <- is.finite(aff.adjust)
                  aff.species[[icomb]]$values[[jspecies]][isfin] <- aff.species[[icomb]]$values[[jspecies]][isfin] + 
                    aff.adjust[isfin]
              }
              if (igroup == 1) 
                  groupx <- basisx
              else groupx <- groupx * basisx
          }
          aff.species[[icomb]]$values <- lapply(aff.species[[icomb]]$values, 
              function(values) values * groupx)
      }
      A.species <- aff.species[[1]]
      for (i in 1:length(A.species$values)) {
          A.values <- lapply(lapply(aff.species, "[[", "values"), 
              "[[", i)
          A.species$values[[i]] <- Reduce("+", A.values)
      }
      allargs <- c(list(bases = bases, blend = blend), list(...))
      return(list(fun = "mosaic", args = allargs, A.species = A.species, 
          A.bases = A.bases, E.bases = E.bases))
  })(bases = list(c("H2S", "HS-", "HSO4-", "SO4-2")), blend = TRUE, 
      stable = list(), pH = c(2, 10), T = 250, P = 500, IS = 0.764692985439889)`: the starting basis does not have H2S
  Backtrace:
      ▆
   1. └─CHNOSZ::mosaic(bases, pH = c(2, 10), T = 250, P = 500, IS = NaCl$IS) at test-mosaic.R:97:2
   2.   ├─base::do.call(mosaic, allargs)
   3.   └─CHNOSZ `<fn>`(...)
  ── Error (test-mosaic.R:136:3): mosaic() - equilibrate() produces equilibrium activities that are consistent with
            stability differences of minerals and multiple groups of changing basis species ──
  Error in `mosaic(bases, Eh = c(-0.5, 0))`: the starting basis does not have SO4-2 and CO3-2
  Backtrace:
      ▆
   1. └─CHNOSZ::mosaic(bases, Eh = c(-0.5, 0)) at test-mosaic.R:136:2
  ── Error (test-protein.info.R:21:3): protein.equil() reports values consistent with Dick and Shock (2011) ──
  Error in `basis.elements()`: basis species are not defined
  Backtrace:
      ▆
   1. └─CHNOSZ::protein.equil(protein, loga.protein = -3) at test-protein.info.R:21:2
   2.   └─CHNOSZ::basis.elements()
  ── Failure (test-retrieve.R:18:3): errors and recalculations produce expected messages ──
  `retrieve("Ti")` did not produce any messages.
  ── Error (test-solubility.R:59:3): backward compatible and new calling styles produce the same results ──
  Error in `solubility(i_aq, O2 = c(-55, -40), T = 125, in.terms.of = "SO4-2")`: please load minerals or gases with species()
  Backtrace:
      ▆
   1. └─CHNOSZ::solubility(i_aq, O2 = c(-55, -40), T = 125, in.terms.of = "SO4-2") at test-solubility.R:59:2
  
  [ FAIL 9 | WARN 0 | SKIP 0 | PASS 591 ]
  Error: Test failures
  Execution halted