![]() | Tips and tricks |
| Prev | Generating R code from GUI settings | Next |
Here are a few assorted tricks which may make writing plugins less tedious:
If you need the value of a GUI setting at several places in you plugin's code, consider assigning it to a variable in JS, and using that instead of fetching it again and again with getString()/getBoolean()/getList(). This is faster, more readable, and less typing all at the same time:
function calculate () {
var narm = ""; // na.rm=FALSE is the default in all functions below
if (getBoolean ("remove_nas")) {
$narm = ", na.rm=TRUE";
}
// ...
echo ("results$foo <- foo (x" + narm + ")\n");
echo ("results$bar <- bar (x" + narm + ")\n");
echo ("results$foobar <- foobar (x" + narm "\n");
// ...
}
The simple helper function makeOption() can make it easier to omit parameters that are at their default value, in many cases:
function calculate () {
var options
//...
// This will do nothing, if VALUE is 0.95 (the default). Otherwise it will append ', conf.int=VALUE' to options.
options += makeOption ("conf.int", getString ("confint"), "0.95");
//...
}
| Prev | Contents | Next |
| Conventions, policies, and background | Up | Writing a help page |