R/examples.R

Defines functions demos examples

Documented in demos examples

# CHNOSZ/examples.R
# Functions to run all examples and demos in the package

examples <- function(save.png = FALSE) {
  # Run examples in each of the CHNOSZ help pages
  .ptime <- proc.time()
  topics <- c("thermo", "examples",
    "util.array", "util.data", "util.expression", "util.legend", "util.plot",
    "util.fasta", "util.formula", "util.misc", "util.seq", "util.units",
    "util.water", "taxonomy", "info", "retrieve", "add.OBIGT", "protein.info",
    "water", "IAPWS95", "subcrt", "Berman",
    "makeup", "basis", "swap.basis", "species", "affinity",
    "solubility", "equilibrate", 
    "diagram", "mosaic", "mix",
    "buffer", "nonideal", "NaCl",
    "add.protein", "ionize.aa", "rank.affinity",
    "DEW", "logB.to.OBIGT", "stack_mosaic"
  )
  plot.it <- FALSE
  if(is.character(save.png))
    png(paste(save.png, "%d.png", sep = ""), width = 500, height = 500, pointsize = 12)
  else if(save.png) plot.it <- TRUE
  for(i in 1:length(topics)) {
    if(plot.it) png(paste(topics[i], "%d.png", sep = ""), width = 500, height = 500, pointsize = 12)
    myargs <- list(topic = topics[i], ask = FALSE)
    do.call(example, myargs)
    if(plot.it) dev.off()
  }
  if(is.character(save.png)) dev.off()
  cat("Time elapsed: ", proc.time() - .ptime, "\n")
}

demos <- function(which = c("sources", "protein.equil", "affinity", "NaCl", "density", 
  "ORP", "ionize", "buffer", "protbuff", "glycinate",
  "mosaic", "copper", "arsenic", "solubility", "gold", "contour", "sphalerite", "minsol",
  "Shh", "saturation", "DEW", "lambda", "potassium", "TCA", "aluminum",
  "AD", "comproportionation", "Pourbaix", "E_coli", "yttrium", "rank.affinity"), save.png = FALSE) {
  # Run one or more demos from CHNOSZ with ask = FALSE, and return the value of the last one
  out <- NULL
  for(i in 1:length(which)) {
    # A message so the user knows where we are
    message("------------")
    if(which[i]=="dehydration" & !save.png) {
      message("demos: skipping dehydration demo as save.png is FALSE")
      next 
    } else message(paste("demos: running '", which[i], "'", sep = ""))
    if(save.png & !which[i] == "dehydration") {
      width <- 500
      height <- 500
      if(which[i] == "comproportionation") width <- 600
      png(paste(which[i], "%d.png", sep = ""), width = width, height = height, pointsize = 12)
    }
    out <- demo(which[i], package = "CHNOSZ", character.only = TRUE, echo = FALSE, ask = FALSE)
    if(save.png & !which[i] == "dehydration") dev.off()
  }
  return(invisible(out))
}

Try the CHNOSZ package in your browser

Any scripts or data that you put into this service are public.

CHNOSZ documentation built on March 31, 2023, 7:54 p.m.