I want to put warning messages into some of my functions to remind myself to change the output file names each time I run them. Is there a way to do this that will allow me to respond to the warning message (i.e. "continue function" or "cancel")? Thanks, Matt
Try this: f <- function() { cat("c to continue, anything else to quit: ") x <- readline() if (x != "c") stop("User forced exit") # rest of function } f() On 6/25/06, Matthew Bridgman <m.bridgman at sbcglobal.net> wrote:> I want to put warning messages into some of my functions to remind > myself to change the output file names each time I run them. Is there a > way to do this that will allow me to respond to the warning message > (i.e. "continue function" or "cancel")? > > Thanks, > Matt > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
One small improvement, the cat can be eliminated: f <- function() { x <- readline("c to continue, anything else to quit: ") if (x != "c") stop("User forced exit") # rest of function } f() On 6/25/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> Try this: > > f <- function() { > cat("c to continue, anything else to quit: ") > x <- readline() > if (x != "c") stop("User forced exit") > # rest of function > } > > f() > > On 6/25/06, Matthew Bridgman <m.bridgman at sbcglobal.net> wrote: > > I want to put warning messages into some of my functions to remind > > myself to change the output file names each time I run them. Is there a > > way to do this that will allow me to respond to the warning message > > (i.e. "continue function" or "cancel")? > > > > Thanks, > > Matt > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > >
You might consider passing the output file name to the function as an argument. Matthew Bridgman wrote on 6/25/2006 10:49 AM:> I want to put warning messages into some of my functions to remind > myself to change the output file names each time I run them. Is there a > way to do this that will allow me to respond to the warning message > (i.e. "continue function" or "cancel")? > > Thanks, > Matt > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Michael H. Prager, Ph.D. Population Dynamics Team NOAA Center for Coastal Habitat and Fisheries Research NMFS Southeast Fisheries Science Center Beaufort, North Carolina 28516 USA http://shrimp.ccfhrb.noaa.gov/~mprager/