R/examples.R

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# CHNOSZ/examples.R
# run examples from the help files, 
# and a function containing extra examples

examples <- function(do.png=FALSE) {
  # run all the examples in CHNOSZ documentation
  .ptime <- proc.time()
  topics <- c("thermo", "sideeffects", "examples",
    "util.array", "util.blast", "util.data", "util.expression",
    "util.fasta", "util.formula", "util.matrix", "util.misc", "util.seq", "util.units",
    "util.water", "taxonomy", "info", "protein.info", "hkf", "water", "IAPWS95", "subcrt",
    "makeup", "basis", "swap.basis", "species", "affinity", "equil.boltzmann", 
    "diagram", "buffer", "nonideal", "add.protein", "protein", "ionize.aa", "more.aa", "read.expr",
    "anim", "objective", "revisit", "transfer", "EOSregress", "wjd")
  plot.it <- FALSE
  if(is.character(do.png))
    png(paste(do.png,"%d.png",sep=""),width=500,height=500,pointsize=12)
  else if(do.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(do.png)) dev.off()
  cat("Time elapsed: ", proc.time() - .ptime, "\n")
}

demos <- function(which=c("sources", "protein.equil", "affinity", "NaCl", "density", 
  "ORP", "revisit", "findit", "ionize", "buffer", "protbuff", "yeastgfp", "mosaic",
  "copper", "solubility", "wjd", "dehydration", "bugstab", "Shh", "activity_ratios"), to.file=FALSE) {
  # run one or more demos from CHNOSZ with ask=FALSE, and return the value of the last one
  for(i in 1:length(which)) {
    # say something so the user sees where we are
    message("------------")
    if(which[i]=="dehydration" & !to.file) {
      message("demos: skipping dehydration demo as to.file is FALSE")
      next 
    } else message(paste("demos: running '", which[i], "'", sep=""))
    if(to.file & !which[i]=="dehydration") {
      if(which[i]=="bugstab") png(paste(which[i], "%d.png", sep=""), width=700, height=500, pointsize=12)
      else png(paste(which[i], "%d.png", sep=""), width=500, height=500, pointsize=12)
    }
    out <- demo(which[i], package="CHNOSZ", character.only=TRUE, echo=FALSE, ask=FALSE)
    if(to.file & !which[i]=="dehydration") dev.off()
  }
  return(invisible(out))
}

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.