[R] Rgui and tcltk

David Firth david.firth at nuffield.oxford.ac.uk
Thu Oct 26 14:31:47 CEST 2000


Brian, thanks for your reply.  All of that sounds plausible.

But...  I played around a bit more and found that if I change the 
button's action function to

testaction<-function(){cat(" \n")
                        cat("Hello\n")
                        flush.console()}

[i.e. just insert cat(" \n") before the output I want to print] all 
seems to work fine and I get just the console output that I want. 
But if the first line is changed again to cat("\n"), i.e. the leading 
space is absent, the problem (disappearing text) is back!  All rather 
puzzling.

David

> > Date: Thu, 26 Oct 2000 11:14:16 +0100
> > From: David Firth <david.firth at nuffield.oxford.ac.uk>
> >
> > I am having a little problem in relation to sending output to the R
> > Console window, when a function is called by pushing a button in a Tk
> > window.  Actually there seem to be two components to the problem:
> >   -- the R prompt does not re-appear until <return> is pressed
>
>That's standard with these TclTk things, even on Unix.  What's
>happening is that the console is still waiting for input, and is
>unaware that another part of the event loop has generated a command and
>hence output. So you can just type new input, without waiting for the prompt.
>
> >   -- text output to the R Console window *disappears* after <return> is
>pressed
>
>I believe it gets overwritten by the input line.  That's an R GUI
>console gotcha.  You should have more success running from Rterm.  We
>need to keep track in the GUI console of where the last output was,
>rather than where we were looking for input.  I've done some work on
>this for the next version, but it is probably not right yet.
>(The same problem occurs when using Rprintf to debug C code.)
>
> > The following, in R 1.1.1 under Windows NT 4, and using Tcl/Tk 8.3,
> > illustrates:
> >
> > library(tcltk)
> > testwindow  <- tktoplevel()
> > testaction<-function(){cat("Hello\n")
> >                         flush.console()}
> > testbutton <- tkbutton(testwindow, text="Click me", command=testaction)
> > tkpack(testbutton)
> >
> > This successfully makes a Tk window with a button.  But pressing the
> > button does not do what I intended.  What I would like is for the
> > button-press to print out "Hello" at the R Console, and return to the
> > R prompt.  I would welcome any hints on how I am going wrong here.
>
>I don't believe it is you!  This is said to be experimental code, and
>there are definitely issues about running two GUIs at once we have
>to think more about.
>
>--
>Brian D. Ripley,                  ripley at 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
>
>


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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