[R] stop further sourcing of an R file

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Nov 14 13:36:36 CET 2003


(Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> writes:

> q() will terminate the entire R session.
> 
> I suspect what Ramakrishna wants is to set a break-point
> in a source file, so as to just read in part of it, and
> then continue in the R session with other things.
> 
> Though not what it's intended for, 'break' will do the job.
> 
> E.g. if test.R contains
> 
>   x<-pi*0.01*(0:200);
>   plot(x,sin(x))
>   break
>   plot(x,cos(x))
> 
> then after
> 
>   source("test.R")
> 
> R will plot the sine curve, but not the cosine curve, exiting
> at 'break' with the message
> 
>   No loop to break from, jumping to top level
> 
> and the R session will still be intact, including any variables
> created in the script.

Similarly, stop() could be used, as, I suspect, anything else that
generates a (non-fatal) runtime error:

> source("t.R")
[1] 1
Error in eval.with.vis(expr, envir, enclos) :
        done
> x
[1] 1
> system("cat t.R")
x <- 1;
print(1)
stop("done")
print(2)


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list