[S] Dialog boxes

Niels Waller (ngwaller@ucdavis.edu)
Tue, 27 Oct 1998 09:38:20 -0800

Several Days ago I posted a note concerning dialog boxes. Several people
have sent me messages saying that they too had difficulty understanding the
S-Plus materials concerning this topic.

I also received several VERY helpful tips that I will pass along to others.

I would like to thank all who sent messages; I especially thank Brian Ripley
and Charlie Roosen for their generous help . My dialog boxes now work!
BTW, I found V&R's complements to their MASS book extremely helpful!


On Sat, 24 Oct 1998, Niels Waller wrote:

> Friends and colleagues,
> Please save me from a mental breakdown.
> I would like to create a simple dialog box. I found the documentation for
> the gui toolkit to be worthless. My needs are very simple. I want a
> to appear on the screen with two prompts:
> Intercept _____
> Slope _____
> Students would type in the two numbers and hit Apply, and then their best
> guesstimate of the regression line would be overlaid on a plot of points.
> can't figure out how to retrieve the numeric values from the dialog box.
> Is there anyone out there that can send me a hint?
I think this is easy. I have no idea what documentation you are reading:
try the account in the V&R on-line programming complements.

Write a simple function

menuReg <- function(Intercept, Slope)
do something

Then the default dialog box for this function (the one you get by
double-clicking on it in the object browser) will do exactly what you want,
plus `Return Value' (the object in which to put the result) which you can
ignore (but may need a value in there). The when you hit Return (and also I
think when you hit Apply) the function menuReg is called with those

Once you have this working, it is not too hard to set up your own dialog
box (see our on-line complements). Something like (I have not tested this)

guiCreate("FunctionInfo", Name = "menuReg",
Function = "menuReg",
DialogHeader = "Enter your guess",
PropertyList = c("regIntercept","regSlope","regSaveAs"),
ArgumentList = "#0=regSaveAs, #1=regIntercept, #2=regSlope")

# replace Invisible by String to get this as a visible entry.
guiCreate("Property", Name="regSaveAs", DialogPrompt="Save As",
DialogControl="Invisible", DefaultValue="last.reg")
guiCreate("Property", Name="regIntercept", DialogPrompt="Intercept",
guiCreate("Property", Name="regSlope", DialogPrompt="Slope",

This may not be the way you were thinking about doing this, but is
the simplest I know.

Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

Hi Niels,

I'll give a pointer or two. I suggest looking at the gaussfit example in Chapter 12 of the Programmer's Guide, particularly the bit starting on Page 402. The samples directory contains a file gaussfit.ssc containing the relevant code, so you can just run the script to create the example functions used in the chapter.

I'm not sure whether you intend to launch the dialog from within a function or from a menu selection. If you intend to use a menu selection, you can do the following:

my.function <- function(a, b) { cat("\n Intercept: ",a,"\n Slope: ",b,"\n") invisible(NULL) }

# Create the menu item to run your function

guiCreate("MenuItem",Name="SPlusMenuBar$MyMethods", Type="Menu", MenuItemText = "&My Methods", Index=11, OverWrite=F)

guiCreate("MenuItem", Name="SPlusMenuBar$MyMethods$MyFunction", Type="MenuItem", Action="Function", Command="my.function", MenuItemText="My &Function")

# Create a FunctionInfo object describing the dialog # Create Property objects for the fields in the dialog

guiCreate("Property", Name="MySlope", DialogPrompt="Slope", DialogControl="String") guiCreate("Property", Name="MyIntercept", DialogPrompt="Intercept", DialogControl="String")

guiCreate("FunctionInfo", Name="my.function", Function="my.function", PropertyList="MyIntercept, MySlope, SPropInvisibleReturnObject", ArgumentList="#0=SPropInvisibleReturnObject, #1=MyIntercept, #2=MySlope")

I have extensive revised doc (about 120 pages) on this stuff which still needs a technical edit before it's ready for publication. I could make this available to you as a PDF file if you're interested.

Cheers, Charlie Roosen

>******************************************************************** >Niels Waller, Ph.D. >Associate Professor > >Address: One Shields Avenue Phone: (530) 752-4459 >Department of Psychology >University of California >Davis, CA 95616 > >Internet: http://psychology.ucdavis.edu/waller >******************************************************************** > >----------------------------------------------------------------------- >This message was distributed by s-news@wubios.wustl.edu. To unsubscribe >send e-mail to s-news-request@wubios.wustl.edu with the BODY of the >message: unsubscribe s-news >

----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news