[R] How to defeat buffering in Rgui?
Spencer Graves
spencer.graves at structuremonitoring.com
Fri Jun 29 19:15:02 CEST 2012
Dear Prof. Ripley:
Thanks for the reply. Unfortunately, flush.console() seems to
lock up my system. I tried the following:
for(i in 1:1e7){
tst <- sin(i)
if((i%%1e5)==0)cat(i, "")
if((i%%1e6)==0)cat('\n')
flush.console()
}
This slows down Rgui 2.15.1 (32-bit) by a factor of roughly 350:
In Rterm (64-bit), on my dual core 64-bit Windows 7 system, this ran to
completion in 1 minute; this same code without flush.console() ran to
completion in 35 seconds in Rgui 2.15.1 (64-bit), then presented the
display. Watching it run in Rgui, it seemed to consume roughly half of
one CPU while making very slow progress. I started timing it when it
displayed 200000; 24 minutes later, I noticed it was displaying
900000. That produces an estimate of 340 minutes to complete.
I'd like to use this to give users (e.g., of a CRAN package) a
progress report on long computations: Otherwise, a user doesn't know if
the computation will every complete.
Suggestions?
Thanks,
Spencer
On 6/29/2012 12:12 AM, Prof Brian Ripley wrote:
> See the posting guide: this is in the FAQ which you are expected to
> consult before posting. See
>
> http://cran.r-project.org/bin/windows/base/rw-FAQ.html#The-output-to-the-console-seems-to-be-delayed
>
>
> and ?flush.console .
>
> On 29/06/2012 08:01, Spencer Graves wrote:
>> Hello, All:
>>
>>
>> Does anyone know how to defeat buffering of output to the console
>> from Rgui? I routinely print progress reports to the console from
>> within Rterm running under Emacs with ESS (Emacs Speaks Statistics); see
>> the example below. However, when I run the same example under Rgui, it
>> queues all the output until the computations are complete.
>>
>>
>> How can I monitor the progress of computations in both Rgui and
>> Rterm?
>>
>>
>> Consider the following:
>>
>>
>> for(i in 1:1e7){
>> tst <- sin(i)
>> if((i%%1e5)==0)cat(i, "")
>> if((i%%1e6)==0)cat('\n')
>> }
>>
>>
>> For Rterm 2.15.1 running under Emacs with ESS (Emacs Speaks
>> Statistics), this prints 10000, then pauses before printing 200000,
>> etc., until it gets to 1000000, printing 10 numbers in each row.
>>
>>
>> However, in Rgui 2.15.1, it queues all the numbers and prints
>> them all together when it completes the computation. The following is
>> similar:
>>
>>
>> for(i in 1:1e7){
>> tst <- sin(i)
>> if((i%%1e5)==0)print(i)
>> if((i%%1e6)==0)cat('\n')
>> }
>>
>>
>>> sessionInfo()
>> R version 2.15.1 (2012-06-22)
>> Platform: i386-pc-mingw32/i386 (32-bit)
>>
>> locale:
>> [1] LC_COLLATE=English_United States.1252
>> [2] LC_CTYPE=English_United States.1252
>> [3] LC_MONETARY=English_United States.1252
>> [4] LC_NUMERIC=C
>> [5] LC_TIME=English_United States.1252
>>
>> attached base packages:
>> [1] stats graphics grDevices utils datasets methods base
>>
>>
>> Thanks,
>> Spencer
>
More information about the R-help
mailing list