[R] R/Tk from batch file

David Lucy dlucy at maths.ed.ac.uk
Tue Jan 29 16:50:28 CET 2002


Dear R-users,

Thank you for your help. I have spent the last day or so playing with the
R/tk functions in windows and got to the point where I have an icon on my
desktop which when double clicked runs the R/tk functions without the
user seeing any of the underlying Rterm.

What I have found is that there is no need to edit the system Rprofile.
The windows version seems to be quite happy to direct it's graphics
output to a standard window by an explicit opening of a device (as
suggested by Brian Ripley, however Brian Ripley also says that the entry
in the system Rprofile will allow new graphic devices to be opened when
needed, for instance in case the graphics device is shut down for any
reason). 

The following function

############################################################
library(tcltk)
control <- tktoplevel()
alpha <- tclVar(1)
windows()
b <- tkbutton(control, text = "Press me")
c <- tkbutton(control, text = "Quit")
tkpack(b)
tkpack(c)
exit <- function(){tkdestroy(control); dev.off()}
change.text <- function()
	{
	tclvalue(alpha) <- as.integer(tclvalue(alpha)) + 1
	barplot(as.integer(tclvalue(alpha)))
	}
tkconfigure(b, command = change.text)
tkconfigure(c, command = exit)
tkwait.window(control)
###########################################################

has windows() on line 4 - if this is #shed out the graphical output goes
to a .ps file. With it in the output goes to a standard windows device.

The second little problem of the toplevel() going down was (again as
suggested) solved by tkwait (I wondered what tkwait did). Rather than use
a tkwait.variable() I used tkwait.window() and get clean operation and
shutdown.

The batch file is in the same directory as the script file consists of:

###########################################################
c:\progra~1\r\rw1040\bin\rterm --slave < test.r
###########################################################

or wherever the Rterm.exe is - I find the progra~1 style of navigating
through the directory system is easiest, rather than messing about with
all the speech marks.

This opens up a little term (or whatever the windows equivalent is) with
an R session in it which takes stdio and stderr - it closes down nicely
when the function exits, however, the term cannot be persuaded to open
iconised. What will open iconised is a link (shortcut) from the desktop,
or menu, to the .bat file (from Peter Dalgaard). This is probably a
Windows 2000 feature? and may be different on other versions of Windows.
Brian Ripley suggests there may be a .pif file which will allow launch as
an icon.

Initially I had used a dev.off() in the exit() - this is required to take
the graphics window down when running from an interactive R session, but
is not really required for non-interactive operation (B. Ripley).

Again, many thanks for your help - the functions will be availible at:

http://www.maths.ed.ac.uk/~dlucy

in the near future.

Dave.


**********************************************************************
**  Dr. David Lucy                                                  **
**  Joseph Bell Centre for Forensic Statistics and Legal Reasoning  **
**  Department of Mathematics and Statistics                        **
**  The University of Edinburgh                                     **
**  James Clerk Maxwell Building                                    **
**  King's Buildings                                                **
**  Mayfield Road                                                   **
**  Edinburgh                                                       **
**  EH9 3JZ                                                         **
**                                                                  **
**  tel: 0131 650 5057                                              **
**  extension: 505057                                               **
**  e-mail: dlucy at maths.ed.ac.uk                                    **
**                                                                  **
**  Truncated address:                                              **
**                                                                  **
**  Dr. David Lucy                                                  **
**  Department of Mathematics                                       **
**  JCMB                                                            **
**  King's Buildings                                                **
**  Edinburgh University                                            **
**  Edinburgh                                                       **
**  EH9 3JZ                                                         **
**********************************************************************



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list