[R] How to skip rest of code

bartjoosen bartjoosen at hotmail.com
Mon May 4 11:08:05 CEST 2009


How about:

x <- F
if (x) {
 print("true") 
} else {
print("false")
}


Bart


mli-2 wrote:
> 
> Dear R users,
>  
> Suppose I have 2 R script files: 'test1.R' and 'test2.R' and one R file
> 'main.R' which sources each of them. I wonder if there is a way to skip
> rest of code in 'test1.R' once a condition is met but still continue to
> run rest of script from the 'main'R' file.
>  
> A simple example is shown below. I hope only 'message1' and 'message3' can
> be shown up without using if(...) else statement for skipped part in
> 'test1.R'.
>  
> #main.R:
> source("test1.R")
> source("test2.R")
> =======================================
> #test1.R
> # In this example the goal is to skip executing the line of
> print("message2").
> # without using if() else statement.
> x <- TRUE
> if (x) {
>     print("message1")
>     q() # want to skip rest of code in test1.R ONLY
> }
> # lots of lines can start from here.
> print("message2")
> =======================================
> #test2.R
> print("message3")
>  
>  
> Thank you.
> Ming-chung Li
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-skip-rest-of-code-tp23320816p23365295.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list