Sorry, I forgot to correct the message subject, so I am resending my doubt it below: Hi all! I wrote a very basic program in R, which has some loops ('for' and 'while'). Is there a way to print the 'for' (or while) indice while the program is running so that I am able to estimate where the program is and how long it will last? I mean, I want something like this: i<-0 While(i<100){ "do a lot of commands" "print i" i<-i+1 } How do I "print" the "i" at each step? Thanks in advance, Marcos
> How do I "print" the "i" at each step?print(i)?
Try this. Look at ?flsuh.console if you are on windows HTH, Andy #~~~~~~~~~~~~~~~~~~~~~~~~ i<-0 while(i<100){ ## "do a lot of commands" ##"print i" cat(i, "\n") ## if using windows flush.console() i<-i+1 }
Use cat() or print(). -roger Marcos Sanches wrote:> Sorry, I forgot to correct the message subject, so I am resending my > doubt it below: > > > Hi all! > > I wrote a very basic program in R, which has some loops ('for' and > 'while'). Is there a way to print the 'for' (or while) indice while the > program is running so that I am able to estimate where the program is > and how long it will last? > > I mean, I want something like this: > > i<-0 > While(i<100){ > "do a lot of commands" > "print i" > i<-i+1 > } > > How do I "print" the "i" at each step? > > Thanks in advance, > > Marcos > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Consider the following: > i <- 0 > while(i < 5) { "do stuff" print(i) i <- i + 1 } [1] 0 [1] 1 [1] 2 [1] 3 [1] 4 > i <- 0 > while(i < 5) { "do stuff" cat(i, "") i <- i + 1 } 0 1 2 3 4 > i <- 0 > while(i < 100) { "do stuff" if((i %% 10) == 0) cat(i, "") i <- i + 1 } 0 10 20 30 40 50 60 70 80 90 This was produced in S-Plus 6.2 under Windows 2000. For some reason, when I copy this code from S-Plus to R1.8.1 via XEmacs, this is locking up R for me right now, and I can't figure out why. However, I see no reason why these constructs would not work in R. hope this helps. spencer graves Marcos Sanches wrote:>Sorry, I forgot to correct the message subject, so I am resending my >doubt it below: > > > Hi all! > > I wrote a very basic program in R, which has some loops ('for' and >'while'). Is there a way to print the 'for' (or while) indice while the >program is running so that I am able to estimate where the program is >and how long it will last? > >I mean, I want something like this: > >i<-0 >While(i<100){ >"do a lot of commands" >"print i" >i<-i+1 >} > >How do I "print" the "i" at each step? > >Thanks in advance, > >Marcos > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
Quoting Marcos Sanches <marcos.sanches at ipsos-opinion.com.br>:> I mean, I want something like this: > > i<-0 > While(i<100){ > "do a lot of commands" > "print i" > i<-i+1 > } > > How do I "print" the "i" at each step?Is print(i) what you want? Cheers, Kevin ------------------------------------------------------------ Ko-Kang Kevin Wang SLC Statistics Workshops Co-ordinator Student Learning Centre University of Auckland New Zealand ------------------------------------------------- This mail sent through University of Auckland http://www.auckland.ac.nz/