From pdalgd at gmail.com  Tue Dec 20 13:54:56 2011
From: pdalgd at gmail.com (peter dalgaard)
Date: Tue, 20 Dec 2011 13:54:56 +0100
Subject: [Rd] Speed issue when writing to RGui console from tcl/tk GUI
In-Reply-To: <CAPp_+=fy1CeZWWAvGqmRG2a0d2v0DTupT-_WvK8OT2W2tsNc7w@mail.gmail.com>
References: <CAPp_+=fy1CeZWWAvGqmRG2a0d2v0DTupT-_WvK8OT2W2tsNc7w@mail.gmail.com>
Message-ID: <5057C72E-A522-40A2-8C70-E75CEE499D2E@gmail.com>


On Dec 19, 2011, at 11:34 , Richard Cotton wrote:

> It seems that there are speed issues when printing to the R console from a
> tcl/tk GUI.
> 
> Here are functions to write a lot of output, and to display how long it
> takes.
> 
> printsalot <- function(n)
> {
>  for(i in 1:n) cat(i, fill = TRUE)
> }
> 
> timings <- function(n = 1e3)
> {
>  print(system.time(printsalot(n)))
> }
> 
> Calling timings() from the console reveals a run time of a few hundredths
> of a second.
> 
> The following GUI has two buttons.  Clicking the "slow" buttons just calls
> timings directly, and takes several seconds to run.  However, if we request
> input from the console, via readline (the "fast" button) then the timing
> drops back down to hundredths of a second.
> 
> library(tcltk)
> win <- tktoplevel()
> btn1 <- ttkbutton(win, text = "slow", command = function() timings())
> btn2 <- ttkbutton(win, text = "fast", command = function() {readline("Press
> ENTER > "); timings()})
> tkpack(btn1, btn2)
> 
> I've only observed this slow behaviour with RGui on Windows (XP) - it
> doesn't happen with Rterminal or eclipse/StatET or RStudio.
> 
> I want a few people to run this code to see if it affects, for example,
> other OSes, to narrow down the extent of the problem before I submit it as
> a bug.
> 

Nothing of the sort is happening on OSX. The RGui console is known to be slow if unbuffered, so you may want to experiment with turning buffering on. It could also be some event handling issue, but it doesn't really seem likely to me.

-pd

> Also, if you have any insight as to what is happening or fixes, I'd be
> interested to know.
> 
> Regards,
> Richie.
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Speed issue when writing to RGui console from tcl/tk GUI
peter dalgaard