[R] how can one break or stop or return from a script?

Don MacQueen macq at llnl.gov
Tue Nov 17 02:31:56 CET 2009


I don't know how to do this in the way you describe.

Easy alternatives include:

  - putting the part of the script that is to be executed 
conditionally into a separate file, and then source it or not based 
on some condition.
   - simply wrapping the different parts of the script in if, then, else blocks.

-Don

At 1:37 PM -0800 11/16/09, Stu wrote:
>Hi,
>
>I am using a script to initialize variables in the global workspace.
>
>Based on some condition, I would like to stop evaluation of a script
>sourced on the command-line, without issuing an error.
>
>My current solution is the following hack that uses a repeat { }
>statement
>
>----------- init.R -----------
>#hack to enable setting of breakpoint
>repeat {
>
>...
>if (condition) {
>     break;
>}
>
>...
>
># remember to break !!
>break;
>} #end repeat
>EOF
>
>Thanks,
>- Stu
>
>______________________________________________
>R-help at r-project.org mailing list
>https://*stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062




More information about the R-help mailing list