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

From: Timothy Bates <timothy.c.bates_at_gmail.com>
Date: Sat, 06 Aug 2011 18:29:16 +0100


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")
   }
}



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 06 Aug 2011 - 20:56:06 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 07 Aug 2011 - 23:10:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive