[R] How could I terminate a script (without leaving R)?

Duncan Murdoch murdoch at stats.uwo.ca
Thu May 28 15:09:43 CEST 2009


On 5/28/2009 8:58 AM, Mario Valle wrote:
> Good morning!
> Which is the preferred method to leave a sourced script and returning back to the '>' prompt?
> 
> For example I search for certain files to be processed, but nothing should be done if they
> are not present. Normally I do in my script:
> f<-dir(pattern="qq")
> if(length(f) > 0) {
>     ...process file list...
> }
> # script end
> 
> But I don't like those {} encompassing the whole script so I'm searching for something to
> put in place of the '???' here:
> f<-dir(pattern="qq")
> if(length(f) == 0) '???'
> ...process file list...
> # script end
> 
> Using stop("No file found", call.=F) works, but the Error message is ugly in this case.
> 
> Any suggestion?

Put the code in a function, call the function as the last line of the 
script, and return from the function when you want to exit the script.

Duncan Murdoch




More information about the R-help mailing list