Description Usage Arguments Details Value Note Author(s) Examples
Prepares a GUI for a function with input fields for all arguments or a subset of them and an output area to show the command that corresponds to the chosen values of the arguments. Next to each input field is a help button for the corresponding argument. When the window is closed the function is run with the selected values of the arguments.
1 2 | my.gui.fun(f, anames, fname = ".f", title = f, getFix, posArg = 0,
encinquotes, helpsFunc = f, truefunname = f)
|
f |
name of a function, a character string. |
anames |
argument names, a list or alist, see Details. |
fname |
name for the internally created function, a character string. Not really relevant for the user. |
title |
a character string to be used as a title of the GUI window. |
getFix |
see Details. |
posArg |
number of positional arguments, a non-negative integer, see Details. |
encinquotes |
not used. |
helpsFunc |
name of the function from which to get the help text,
defaults to |
truefunname |
name of the function to actually use in the generated command, see Details. |
my.gui.fun
creates a GUI window for a function. The window
contains input fields for all arguments or a selected subset of them
and allows the user to set their values. Some arguments get special
fields. For example, logical arguments may be presented as radio
buttons instead of input fields and arguments that are
supposed to be filenames may be set also by standard browsing. Due to
the semantics of R the automatic detection of such fields is limited
and may be wrong.
Next to each input field is a help button for the corresponding argument. It is obtained from the relevant Rd documentation.
When the window is closed the function is run with the selected values of the arguments as if from the command line and the result is returned.
An output area in the GUI window shows the command that corresponds to the chosen values of the arguments. The user may experiment with different choices and on closing the window the last command is run as if from the command line.
By default, input fields are created for all arguments of the function with the initial values set to the default ones, were available.
Argument anames
can be used to specify a subset of the
arguments of f
for which input fields and help are to be
provided and/or to change the initial values. It is a named list (or
alist) whose names are argument names and the values in the list are
initial values for the corresponding arguments. If initial values are
not required for all arguments, then anames
should be an
alist
, see the examples.
The command generated by my.gui.fun
contains named arguments.
Many functions however are normally called with one or two unnamed
arguments, possibly followed by named ones. Argument posArg
can
be used to get this effect. It requests that the first posArg
arguments in the generated command are positional.
Argument helpsFunc
requests that the information for the
arguments be taken from helpsFunc
, not f
. This may be
useful when the requested arguments of f
coincide with those of
helpsFunc
. This may happen, for example, when
f
is a simplified wrapper for helpsFunc
. Classes of
mathematical functions also have similar arguments.
truefunname
specifies the function name to be put in the
generated command in place of f
. This may be desirable, for
example, when presenting dialogs for methods for S3 generic functions,
such as plot.lm
and plot.ts
, when it is preferable to
use the base name only and in some cases, e.g. plot.acf
, the
method may not be visible for direct use.
Argument getFix
should be rarely needed. It allows some control
over the hadling of arguments in case some names automaticaly obtained
by deparse/substitute (todo: give more details here).
On exit, the generated command is run. So the value is whatever it returns.
I use this function in menus to present students with simplified signatures of built in R functions, gradually introducing more arguments.
Argument getFix
here is similar to that in fgui's
function gui()
but it has a different default and here we allow
individual settings for the arguments, since sometimes a blanket
setting for all of them does not work nicely.
Georgi N. Boshnakov
1 2 3 4 5 6 7 8 9 10 11 12 13 | # my.gui.fun("rnorm", posArg=1)
#
# Input field only for all arugments, all named
# my.gui.fun("rexp")
# Input field only for n (positional)
# my.gui.fun("rexp", alist(n=10), posArg=1)
# both args, but no initial value for rate
# my.gui.fun("rexp", alist(n=10,rate=), posArg=1)
# more arguments, one of them logical
# my.gui.fun("pf", alist(q=,df1=,df2=, lower.tail = TRUE), posArg=1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.