[R] GO TO function in R

William Dunlap wdunlap at tibco.com
Fri Aug 2 04:17:10 CEST 2013


There is no 'GO TO'.

Try wrapping your code in a while(TRUE){...} loop.
   while(TRUE) {
        ... do something ...
        Sys.sleep(time)
   }
Or you could have it read from a named pipe which some other process
feeds.
   while(length(readLines(n=1, "someNamedPipe"))==1) {
      ... do something ...
   }

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Peter Maclean
> Sent: Thursday, August 01, 2013 6:58 PM
> To: r-help at r-project.org
> Subject: Re: [R] GO TO function in R
> 
> Does R has a GO TO function? For example, I want to run this script at a given interval
> and save the results.
> 
> #Step one
> a <- Sys.time()
> b <- paste("Figure_", a, sep = " ")
> shape <- as.numeric(a)/100000000
> scale <- as.numeric(a)/10000000000
> #I want to save the file using "b" object (above) as a file name
> #However it is saved as b.pdf
> pdf("f:/b.pdf") #How to save the file using "b" above?
> par(mfrow=c(2,1))
> x <- sort(rgamma(100, shape=shape, scale = scale))
> y <- dgamma(x, shape=shape, scale = scale)
> par(mfrow=c(2,1))
> plot(x, y, type="l",col="red", lwd=5)
> 
> #Step 2
> Sys.sleep(2) # For Quick results in the model it is one hour
> shape <- (as.numeric(Sys.time()))/100000000
> scale <- (as.numeric(Sys.time()))/10000000000
> x <- sort(rgamma(100, shape=shape, scale = scale))
> y <- dgamma(x, shape=shape, scale = scale)
> plot(x, y, type="b",col=" dark red", lwd=5)
> dev.off()
> #Step 3
> Sys.sleep(2) Again in the model it is one hour
> #I Want to go back to step 1 to start over again
> 
> 
> Sincerely,
> 
> Peter Maclean
> Department of Economics
> UDSM
> 	[[alternative HTML version deleted]]



More information about the R-help mailing list