Re: [R] Show Progress in loop

2005-10-10 Thread Prof Brian Ripley
On Mon, 10 Oct 2005, Philippe Grosjean wrote:

> Hello,
>
> You must explicitly use print(), show() on an object -here, use
> print(i)- in a loop or alternatively, use cat() to display string like:
> cat("loop", i, "\n")
>
> With RGui under Windows, there is another subtility: if you have turn on
> 'Misc -> Buffered output' (it is ON by default), all output are delayed
> until the end of the command processing. You need to use flush.console()
> to tell to print i immediatelly within a loop. The best synthax is
> (since the command is only usable under Windows):

Not so: all systems have it.  It is also useful on MacOS X.  All this is 
on the help page.

This is in the rw-FAQ: it seems we have lost the convention of not 
answering FAQs but referring people to the appropriate FAQ.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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


Re: [R] Show Progress in loop

2005-10-10 Thread ernesto
Rainer M. Krug wrote:

>Hi
>
>I have a loop which is doing time consuming calculations and I would 
>like to be able to have some feedback on where it is in it's 
>calculations. I tried to simply show the counter variable in the loop, 
>but id doesn't work as all display seems to be delayed until the loop is 
>completed. Is there any way of displaying the progress of a loop?
>
>Rainer
>
>The loop:
>
>for (i in 2:Result$NoSims)
>{
>   ppp <- runifpoint(Result$NoPlants)
>   K <- Kest(ppp)
>   Result$LSim[i,] <- sqrt(K$iso / pi) - K$r
>   CM <- (Result$LSim[i,] * Result$LSim[i,]) / abs(K$r[2] - K$r[1])
>   Result$SigCM[i] <- sum(CM, na.rm=TRUE)
>   i  #}
>
>  
>
Hi,

You can simply include a command like

cat("loop: " , i, "\n")

inside your loop.

EJ

__
R-help@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


Re: [R] Show Progress in loop

2005-10-10 Thread vincent
Rainer M. Krug a écrit :

> Hi
> I have a loop which is doing time consuming calculations and I would 
> like to be able to have some feedback on where it is in it's 
> calculations. I tried to simply show the counter variable in the loop, 
> but id doesn't work as all display seems to be delayed until the loop is 
> completed. Is there any way of displaying the progress of a loop?
> 
> for (i in 2:Result$NoSims)
> {
>   ...
>   i  # }
> 

Hi,
for your last line, use :

print(i);
flush.console();  #<== now displays in the loop

hih

__
R-help@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


Re: [R] Show Progress in loop

2005-10-10 Thread Peter Dalgaard
"Rainer M. Krug" <[EMAIL PROTECTED]> writes:

> I put print(i) in the loop instead of i, but it still only prints (in 
> the Windows R GUI) i after it finished the calculations.
> I guess it might be due to the output buffering you mentioned - but how 
> do I unset it?

Using the user friendly interface... (it's on one of the top menus),
or, as Uwe suggested, stick in flush.console() after the print(i).

-p
 
> Rainer
> 
> Peter Dalgaard wrote:
> > "Rainer M. Krug" <[EMAIL PROTECTED]> writes:
> > 
> > 
> >>Hi
> >>
> >>I have a loop which is doing time consuming calculations and I would 
> >>like to be able to have some feedback on where it is in it's 
> >>calculations. I tried to simply show the counter variable in the loop, 
> >>but id doesn't work as all display seems to be delayed until the loop is 
> >>completed. Is there any way of displaying the progress of a loop?
> >>
> >>Rainer
> >>
> >>The loop:
> >>
> >>for (i in 2:Result$NoSims)
> >>{
> >>ppp <- runifpoint(Result$NoPlants)
> >>K <- Kest(ppp)
> >>Result$LSim[i,] <- sqrt(K$iso / pi) - K$r
> >>CM <- (Result$LSim[i,] * Result$LSim[i,]) / abs(K$r[2] - K$r[1])
> >>Result$SigCM[i] <- sum(CM, na.rm=TRUE)
> >>i  # >>}
> > 
> > 
> > Just print(i) and if on Windows, remember to unset output buffering. 
> > 
> 
> 
> 
> -- 
> NEW TELEPHONE NUMBER
> Tel:  +27 - (0)72 808 2975 (w)
> 
> Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
> Biology (UCT)
> 
> Department of Conservation Ecology
> University of Stellenbosch
> Matieland 7602
> South Africa
> 
> Tel:  +27 - (0)72 808 2975 (w)
> Fax:  +27 - (0)21 808 3304
> Cell: +27 - (0)83 9479 042
> 
> email:[EMAIL PROTECTED]
>   [EMAIL PROTECTED]
> 
> __
> R-help@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
> 

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@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


Re: [R] Show Progress in loop

2005-10-10 Thread Philippe Grosjean
Hello,

You must explicitly use print(), show() on an object -here, use 
print(i)- in a loop or alternatively, use cat() to display string like:
cat("loop", i, "\n")

With RGui under Windows, there is another subtility: if you have turn on 
'Misc -> Buffered output' (it is ON by default), all output are delayed 
until the end of the command processing. You need to use flush.console() 
to tell to print i immediatelly within a loop. The best synthax is 
(since the command is only usable under Windows):
 > for (i in 1:10) {
 >  print(i)# You must use print explicitly within a loop
 >  # or, better, use: cat("loop", i, "\n")
 >  # Next command is to overcome buffered output in RGui
 >  if (.Platform$OS.type == "windows") flush.console()
 >  # Next command simulates a "long" process (taking 1 sec)
 >  Sys.sleep(1)
 >  # ... your loop code here...
 > }

Alternatively, you can use the progress() function in svMisc package 
(SciViews bundle). Load svMisc and look at its online help... you have 
several examples of use.
 > library(svMisc)
 > ?progress

Best,

Philippe Grosjean

..<°}))><
  ) ) ) ) )
( ( ( ( (Prof. Philippe Grosjean
  ) ) ) ) )
( ( ( ( (Numerical Ecology of Aquatic Systems
  ) ) ) ) )   Mons-Hainaut University, Pentagone (3D08)
( ( ( ( (Academie Universitaire Wallonie-Bruxelles
  ) ) ) ) )   8, av du Champ de Mars, 7000 Mons, Belgium
( ( ( ( (
  ) ) ) ) )   phone: + 32.65.37.34.97, fax: + 32.65.37.30.54
( ( ( ( (email: [EMAIL PROTECTED]
  ) ) ) ) )
( ( ( ( (web:   http://www.umh.ac.be/~econum
  ) ) ) ) )  http://www.sciviews.org
( ( ( ( (
..

Rainer M. Krug wrote:
> Hi
> 
> I have a loop which is doing time consuming calculations and I would 
> like to be able to have some feedback on where it is in it's 
> calculations. I tried to simply show the counter variable in the loop, 
> but id doesn't work as all display seems to be delayed until the loop is 
> completed. Is there any way of displaying the progress of a loop?
> 
> Rainer
> 
> The loop:
> 
> for (i in 2:Result$NoSims)
> {
>   ppp <- runifpoint(Result$NoPlants)
>   K <- Kest(ppp)
>   Result$LSim[i,] <- sqrt(K$iso / pi) - K$r
>   CM <- (Result$LSim[i,] * Result$LSim[i,]) / abs(K$r[2] - K$r[1])
>   Result$SigCM[i] <- sum(CM, na.rm=TRUE)
>   i  # }
>

__
R-help@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


Re: [R] Show Progress in loop

2005-10-10 Thread Rainer M. Krug
Thanks - flush.console() did the trick.

As you might guess, I am quite new to R. I like the idea of vectorizing 
the calculation, but I guess it is not possible in this case - I will 
ask in a new thread.

Thanks,

Rainer


Uwe Ligges wrote:
> Rainer M. Krug wrote:
> 
>> Hi
>>
>> I have a loop which is doing time consuming calculations and I would 
>> like to be able to have some feedback on where it is in it's 
>> calculations. I tried to simply show the counter variable in the loop, 
>> but id doesn't work as all display seems to be delayed until the loop 
>> is completed. Is there any way of displaying the progress of a loop?
>>
>> Rainer
>>
>> The loop:
>>
>> for (i in 2:Result$NoSims)
>> {
>> ppp <- runifpoint(Result$NoPlants)
>> K <- Kest(ppp)
>> Result$LSim[i,] <- sqrt(K$iso / pi) - K$r
>> CM <- (Result$LSim[i,] * Result$LSim[i,]) / abs(K$r[2] - K$r[1])
>> Result$SigCM[i] <- sum(CM, na.rm=TRUE)
>> i  #> }
>>
> 
> 
> - Update your console (I guess you are on Windows?) by using 
> flush.console().
> - You might want to measure time consumption, hence see ?Rprof.
> - Save some more time by moving as much as possible out of your loop by 
> doing it in a vectorized way (I don't know all the functions you are 
> using, hence cannot make any further recommendations).
> 
> Uwe Ligges



-- 
NEW TELEPHONE NUMBER
Tel:+27 - (0)72 808 2975 (w)

Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Department of Conservation Ecology
University of Stellenbosch
Matieland 7602
South Africa

Tel:+27 - (0)72 808 2975 (w)
Fax:+27 - (0)21 808 3304
Cell:   +27 - (0)83 9479 042

email:  [EMAIL PROTECTED]
[EMAIL PROTECTED]

__
R-help@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


Re: [R] Show Progress in loop

2005-10-10 Thread Rainer M. Krug
I put print(i) in the loop instead of i, but it still only prints (in 
the Windows R GUI) i after it finished the calculations.
I guess it might be due to the output buffering you mentioned - but how 
do I unset it?

Rainer

Peter Dalgaard wrote:
> "Rainer M. Krug" <[EMAIL PROTECTED]> writes:
> 
> 
>>Hi
>>
>>I have a loop which is doing time consuming calculations and I would 
>>like to be able to have some feedback on where it is in it's 
>>calculations. I tried to simply show the counter variable in the loop, 
>>but id doesn't work as all display seems to be delayed until the loop is 
>>completed. Is there any way of displaying the progress of a loop?
>>
>>Rainer
>>
>>The loop:
>>
>>for (i in 2:Result$NoSims)
>>{
>>  ppp <- runifpoint(Result$NoPlants)
>>  K <- Kest(ppp)
>>  Result$LSim[i,] <- sqrt(K$iso / pi) - K$r
>>  CM <- (Result$LSim[i,] * Result$LSim[i,]) / abs(K$r[2] - K$r[1])
>>  Result$SigCM[i] <- sum(CM, na.rm=TRUE)
>>  i  #>}
> 
> 
> Just print(i) and if on Windows, remember to unset output buffering. 
> 



-- 
NEW TELEPHONE NUMBER
Tel:+27 - (0)72 808 2975 (w)

Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Department of Conservation Ecology
University of Stellenbosch
Matieland 7602
South Africa

Tel:+27 - (0)72 808 2975 (w)
Fax:+27 - (0)21 808 3304
Cell:   +27 - (0)83 9479 042

email:  [EMAIL PROTECTED]
[EMAIL PROTECTED]

__
R-help@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


Re: [R] Show Progress in loop

2005-10-10 Thread Uwe Ligges
Rainer M. Krug wrote:

> Hi
> 
> I have a loop which is doing time consuming calculations and I would 
> like to be able to have some feedback on where it is in it's 
> calculations. I tried to simply show the counter variable in the loop, 
> but id doesn't work as all display seems to be delayed until the loop is 
> completed. Is there any way of displaying the progress of a loop?
> 
> Rainer
> 
> The loop:
> 
> for (i in 2:Result$NoSims)
> {
>   ppp <- runifpoint(Result$NoPlants)
>   K <- Kest(ppp)
>   Result$LSim[i,] <- sqrt(K$iso / pi) - K$r
>   CM <- (Result$LSim[i,] * Result$LSim[i,]) / abs(K$r[2] - K$r[1])
>   Result$SigCM[i] <- sum(CM, na.rm=TRUE)
>   i  # }
> 


- Update your console (I guess you are on Windows?) by using 
flush.console().
- You might want to measure time consumption, hence see ?Rprof.
- Save some more time by moving as much as possible out of your loop by 
doing it in a vectorized way (I don't know all the functions you are 
using, hence cannot make any further recommendations).

Uwe Ligges

__
R-help@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


Re: [R] Show Progress in loop

2005-10-10 Thread Peter Dalgaard
"Rainer M. Krug" <[EMAIL PROTECTED]> writes:

> Hi
> 
> I have a loop which is doing time consuming calculations and I would 
> like to be able to have some feedback on where it is in it's 
> calculations. I tried to simply show the counter variable in the loop, 
> but id doesn't work as all display seems to be delayed until the loop is 
> completed. Is there any way of displaying the progress of a loop?
> 
> Rainer
> 
> The loop:
> 
> for (i in 2:Result$NoSims)
> {
>   ppp <- runifpoint(Result$NoPlants)
>   K <- Kest(ppp)
>   Result$LSim[i,] <- sqrt(K$iso / pi) - K$r
>   CM <- (Result$LSim[i,] * Result$LSim[i,]) / abs(K$r[2] - K$r[1])
>   Result$SigCM[i] <- sum(CM, na.rm=TRUE)
>   i  # }

Just print(i) and if on Windows, remember to unset output buffering. 

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@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


[R] Show Progress in loop

2005-10-10 Thread Rainer M. Krug
Hi

I have a loop which is doing time consuming calculations and I would 
like to be able to have some feedback on where it is in it's 
calculations. I tried to simply show the counter variable in the loop, 
but id doesn't work as all display seems to be delayed until the loop is 
completed. Is there any way of displaying the progress of a loop?

Rainer

The loop:

for (i in 2:Result$NoSims)
{
ppp <- runifpoint(Result$NoPlants)
K <- Kest(ppp)
Result$LSim[i,] <- sqrt(K$iso / pi) - K$r
CM <- (Result$LSim[i,] * Result$LSim[i,]) / abs(K$r[2] - K$r[1])
Result$SigCM[i] <- sum(CM, na.rm=TRUE)
i  #