[R] Displaying Iteration Count

Paul paul at paulhurley.co.uk
Tue Jun 22 21:58:31 CEST 2010


Downey, Patrick wrote:
> Hello,
>
> I'm running a very long for loop that usually takes hours. For my own piece
> of mind, it would be nice if I could check periodically and see which
> iteration the loop is on. A line of code that told R to print the iteration
> number every 100 or 200 iterations would be perfect.
>
> Does anyone know something like this? I've never known how to print
> anything within a for loop before the loop ends.
>
> Thanks,
> Mitch
>   
You can also use message() to print a message to the console during 
execution (I often do this while debugging functions)

use paste to put the required text together

i.e

for(i in 1:10){
#some code
message(paste("Iteration ",i," of 10",sep=""))
#more code
}

Regards

Paul.



More information about the R-help mailing list