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? Thanks for your help! mario -- Ing. Mario Valle Data Analysis and Visualization Group | http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
Duncan Murdoch
2009-May-28 13:09 UTC
[R] How could I terminate a script (without leaving R)?
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