Download PBS Modelling User's Guide
Transcript
–8–
Although the type argument (like vector) for a widget can never be abbreviated,
other arguments follow the convention used with named arguments in R function calls. For a
given widget type, the available arguments can be abbreviated, as long as the abbreviations
uniquely identify each argument. For example, the vector in Table 1 could be specified as:
vector len=4 nam="m n phi k"
\
lab="'x cycles' 'y cycles' 'y phase' points" \
val="2 3 0 1000"
Unlike variable names in R, widget names and their arguments are not case sensitive.
Some users may prefer to write all type variables in upper case or with an initial capital letter.
For example, the names WINDOW, VECTOR, RADIO, and BUTTON could be used to
emphasize the widgets in Table 1.
2.3. Window support functions
PBS Modelling includes functions designed to connect R code with GUI windows. Every
window has a name argument (with default name=window), and windows with different
names can coexist. Window names must use only letters and numbers; they cannot contain a
period (dot) or any other punctuation. When running a program with multiple windows, only one
window will be current (i.e., selected by the user) at any particular time. Normally, a user selects
a window by clicking on it, but the function focusWin allows program control of the window
currently in focus. Thus, activity in one window might be used to shift the focus to another.
The function createWin uses a description file to generate one or more windows,
where each window has a distinct name (perhaps the default) taken from the file. If a window
with the specified name already exists, it will be closed before the new window is opened. When
designing and testing a GUI, this feature ensures that a new version automatically replaces the
previous one. The function closeWin, which takes a vector of window names, closes all
windows named in the vector. With no arguments, closeWin() closes all windows that are
currently open.
Although createWin normally builds a GUI from a description file, it will also accept
a vector of strings equivalent to such a file. Thus, a file of R source code can define a GUI
directly, without the need for a separate description file. illustrates how this can be done in a
simple case. To see the character vectors equivalent to a given description file (say,
winDesc.txt), type the R command:
scan("winDesc.txt",what=character(),sep="\n")
In particular, if the description file includes a backslash or double quote character, the
corresponding R string must represent it as \\ or \", respectively. Despite this alternative of
embedding window descriptions in R source files, we recommend writing separate files to define
GUIs, except perhaps for very simple models.