[R] Platform independent dialogs & menus?

Philippe Grosjean phgrosjean at sciviews.org
Mon Mar 20 14:17:36 CET 2006


Keith Chamberlain wrote:
> Dear list mates,
> 
> Are {utils} dialog box functions, and winMenuAdd... functions used to change
> (e.g. Console) menus, platform dependent? 

Yes, Windows-only as the 'win' prefix suggests it.

> I'm writing a script loaded with .First that provides first time users in a
> lab course with the ability to select, load, and change between what I
> called a 'session' (more specific save that focuses on the session object I
> defined rather than the whole workspace, & intended to run many different
> sessions through the course of what would be one workspace).

See also the 'session' package on CRAN for that.

> I'm using winMenuAdd() calls to generate their 'Session' menu at startup,
> the menus call functions sourced in for the menu actions. In the menu
> actions, I call routines that use select.list() and file.choose() calls to
> interact with users. 
> 
> I do not work with Macs often, and from what I've gathered today in posts
> about cross-platform difficulties, my sense of being intimidated "seems"
> well placed to me (then again, breaks & some sleep would probably help). I
> have not had the chance to test routines on a Mac yet, so I have no idea
> what to expect. Is this tract I took with winMenuAdd() & related [{utils}
> windows build] an appropriate route to take wrt the Mac build of R, or would
> I be better off using another package? 

For a platform-independent way of defining menus (you will have a 
floating window with your menu), look at ?MenuAdd in package svWidgets 
(SciViews bundle). With these functions, you even have more control on 
the menus (define shortcuts, trigger the menus through R code, for 
instance), and you can define your menu in one R instruction and a 
simple text file to describe the menu structure, like this:

# Create a Tk window then add a menu to it
$MyTkWindow
|$MenuTest
||Objects  ~~ ls()
||-
||Path	   ~~ search()

# Add menus to the RGui console (Windows only)
$ConsoleMain
|$Testit
||One	  ~~ cat("One triggered!\n")
||-
||Two	  ~~ cat("Two triggered!\n")  ~~ state = "disable"
||$SubMenu
|||Three  ~~ cat("Three triggered!\n")
|||Four	  ~~ cat("Four triggered!\n")
||Five	  ~~ cat("Five triggered!\n")

# Add menu to the RGui console popup (Windows only)
$ConsolePopup
|$TestitPopup
||Six	  ~~ cat("Six triggered!\n")

If the preceeding menu definition is in a file named "Menus.txt" in the 
/gui subdirectory of your "MyPackage" package, you can do:

library(svWidgets)
 > tkWinAdd("MyTkWindow", title = "Menu window", pos ="-40+20")
 > MenuReadPackage("MyPackage")

... and you got all your menus configured at once (for MyTkWindows + 
RGui console + RGui console popup menu

Best,

Philippe Grosjean

> Please advise,
> KeithC.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list