[Rd] adding examples of stop and break to function.Rd and Control.Rd

Timothy Bates timothy.c.bates at gmail.com
Sat Aug 6 19:29:16 CEST 2011


function.Rd currently has no example of "stop", Similarly in Control.Rd, there is currently no example of break: these might be helpful for users.

function.Rd suggestion:
# Often it is useful to be able to exit a function on some condition: Use "stop" to do this
testJunk <- function(junk) {
	if( is.null(junk)) {
		stop("Junk must not be null!")
	}	
}
junk=NULL
testJunk(junk)



Control.Rd suggestion:

# Example using break: prints n unless n^2 exceeds 9: in which case it exits the loop.

for(n in 1:5) {
   if(n^2>9){
   	break
   } else {
   	cat(n,"\n")
   }
}



More information about the R-devel mailing list