runModel: Minimalistic generic model interface

Description Usage Arguments Value Note Author(s) Examples

Description

Wrapper function to run an arbitrarily complex model using a minimalistic interface.

Usage

1
runModel(model, input, outdir)

Arguments

model

Function representing the model. It is called as model(input, outdir).

input

List with model inputs. See below for expected contents.

outdir

Name of an existing directory where any output files created by model should be stored. Do not assume that model cares/warns for existing files in outdir.

Value

The return value of model.

Note

The following columns are mandatory in data frame input:

Author(s)

David Kneis david.kneis@tu-dresden.de

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# This model does no computations, it only creates a html table of its inputs
input= list(tbl=data.frame(name=c("a","b"), value=1:2))
model= function(input, outdir) {
  html= paste0("<table border=1>\n  <tr><th> ",paste(names(input$tbl),
    collapse=paste0(" </th><th> "))," </th></tr>\n")
  for (i in 1:nrow(input$tbl)) {
    html= paste0(html,"  <tr>",paste0("<td style='text-align:right'> ",
      unlist(input$tbl[i,])," </td>",collapse=""),"</tr>\n")
  }
  html= paste0(html,"</table>\n")
  write(file=paste(outdir,"out.html",sep="/"), x=html)
  return(invisible(NULL))
}
outdir=tempdir()
runModel(model=model, input=input, outdir=outdir)

dkneis/diatools documentation built on May 15, 2019, 9:12 a.m.