Interactive manipulation of R expressions

Share:

Description

twiddle automatically creates a GUI for interactively manipulating variables in an R expression expr. This GUI will contrain a control, i.e. a slider or a checkbox, for every unbound variable in expr. expr is re-evaluated every time the user changes a control after binding the unbound variables in expr to the new settings of their associated controls. This allows easy interactive exploration of parameter spaces.

Usage

1
2
3
  twiddle(expr, ..., eval = TRUE, auto = TRUE,
    label = NULL, envir = parent.frame(),
    enclos = if (is.list(envir) || is.pairlist(envir)) parent.frame() else baseenv())

Arguments

expr

The expression to manipulate through GUI controls. A control is automatically created for every variable in expr that is not bound in the caller's environment, unless auto is set to FALSE.

eval

If set to FALSE, expr is not evaluated automatically each time a control is operated by the user. Instead, an "eval" button is added to the GUI to trigger manual evaluation.

auto

If set to FALSE, no controls for unbound variables will be created automatically. Unbound variables in expr will remain unbound, unless explicitly bound in the ... parameter.

label

The text label of twiddler dialog.

envir

The environment in which expr is to be evaluated. May also be NULL, a list, a data frame, a pairlist or an integer as specified to sys.call.

enclos

Relevant when envir is a (pair)list or a data frame. Specifies the enclosure, i.e., where R looks for objects not found in envir. This can be NULL (interpreted as the base package environment) or an environment.

...

Optional configuration information for the controls for unbound variables in expr. This information is supplied in the form variable_name = twiddlerControl, ... (e.g. x = knob(lim = c(0, 10)), b = toggle(default = TRUE)). If no twiddlerControl object is supplied for an unbound variable, a knob with range [0.0, 1.0] is created as a default. This behaviour can be suppressed by setting the auto parameter to FALSE.

Value

The last values of the twiddlers as a named list.

Note

If you use an expr that generates console output as a side-effect, e.g. via print, and you are running Windows, you might need to use twiddle_print to see the output in realtime.

See Also

knob, combo, entry, filer, and toggle

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
twiddle(print(x))
twiddle(print(x), eval = FALSE)
twiddle(print(a && !b), a = toggle(), b = toggle())
twiddle(curve(sin(a * x) + cos(b * x), type = "l", col = "darkblue"),
        a = knob(c(0, 0.1), 0.001),
        b = knob(c(0, 0.2), 0.001),
        auto = FALSE)
twiddle(plot(rnorm(100), type=t), t=combo("p", "l", "b"))

## End(Not run)