[R] GO TO function in R

David Winsemius dwinsemius at comcast.net
Fri Aug 2 04:20:10 CEST 2013


On Aug 1, 2013, at 6:58 PM, Peter Maclean wrote:

> Does R has a GO TO function? For example, I want to run this script at a given interval and save the results.
>  

Generally communication is more effective if you make your goals clear in a natural language (English in the case of this mailing list) first.

> #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?

Perhaps:

pdf(file=paste0("f:/", b, ".pdf"))

> 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

# .... "it"?      It would help if you explained what "it" is.

> #I Want to go back to step 1 to start over again
> 

I think is a measure of my success in training my mind to think functionally that I cannot conceive of how I would use GOTO as a function.

(Using `replicate`, I can imagine.)

-- 
David.
> 
> Sincerely,
> 
> Peter Maclean
> Department of Economics
> UDSM
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list