## the following lines define a menu that does not make
## too much sense, but shows the various kinds of buttons
quadratic <- function(d, v, a, mini=0, maxi=Inf) {
d <- pmin(1, pmax(0, d)) - 0.5
d <- ((d>0) * 2 - 1) * d^2 * a * 4
if (missing(v)) d else pmax(mini, pmin(maxi, v + d))
}
simulate <- function(H, par) { ## not a serious example
Print(c(H$x$var, par, runif(1)))
return(H) ## the function must return the first parameter
}
entry <- list(
list(name="Nonsense Menu"),
list(name="Simulate!", val="simulate", col="blue"),
list(name="show H", val="str(H)", col="blue"),
list(name="colx", var="colour",
val=c("red", "green", "blue", "brown")),
list(name="open", var="closed", val=FALSE, par=4.5),
list(name="modifying", var="modify", val=TRUE, par=5),
list(name="probability", var="probab", delta=FALSE,
val=function(d, v) pmin(1, pmax(0, d))),
list(name="variance", var="var", delta=TRUE,
val=function(d, v) quadratic(d, v, 10)),
list(name="name", var="name", par=3, cond="modify")
)
scr <- split.screen(rbind(c(0, 0.45, 0, 1), c(0.5, 1, 0, 1)))
## before proceeding make sure that both the screen and the xterm
## are completely visible
H <- list(modify=5, x=list()) # note that in this example eval.parameters
## will be called by by H$x, hence modify=5 will be left
## unchanged.
options(locatorBell=FALSE) useraction("start.register") ## registring the user's input
Print(eval.parameters("H$x", entry, simulate, update=TRUE, dev=scr[2],
H=H, par=17)) # do not forget to call by name
getactions()
## replay the user's input
useraction("replay")
Print(eval.parameters("H$x", entry, simulate, update=TRUE, dev=scr[2],
H=H, par=17))
Run the code above in your browser using DataLab