Josh
2008-Jun-12 22:52 UTC
[R] Getting Batch mode to continue running a script after running into errors
I'm invoking R in batch mode from a bash script as follows: R --no-restore --no-save --vanilla <$TARGET/$directory/o2sat-$VERSION.R> $TARGET/$directory/o2sat-$VERSION.Routput When R comes across some error in the script however it seems to halt instead of running subsequent lines in the script: Error in file(file, "r") : cannot open the connection Calls: read.table -> file In addition: Warning message: In file(file, "r") : cannot open file '/datapool/experiments/ois/080502/petri': No such file or directory Execution halted How can I get R to continue running the script even if it comes across errors? Thanks in advance
Erin Hodgess
2008-Jun-12 23:55 UTC
[R] Getting Batch mode to continue running a script after running into errors
There is a "try" function that you can wrap around functions. Hope this helps! Sincerely, Erin On 6/12/08, Josh <jcchang at mednet.ucla.edu> wrote:> I'm invoking R in batch mode from a bash script as follows: > > R --no-restore --no-save --vanilla > <$TARGET/$directory/o2sat-$VERSION.R> > $TARGET/$directory/o2sat-$VERSION.Routput > > When R comes across some error in the script however it seems to halt > instead of running subsequent lines in the script: > > Error in file(file, "r") : cannot open the connection > Calls: read.table -> file > In addition: Warning message: > In file(file, "r") : > cannot open file '/datapool/experiments/ois/080502/petri': No such > file or directory > Execution halted > > > How can I get R to continue running the script even if it comes across > errors? Thanks in advance > > ______________________________________________ > 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. >-- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com
Prof Brian Ripley
2008-Jun-13 06:37 UTC
[R] Getting Batch mode to continue running a script after running into errors
?stop explains why this happens and how to change it. You can also set options(error=expression(NULL)) to ignore all errors, and use tryCatch() (or its wrapper try()) skip particular expressions if tjhey fail. But surely in your example your script should check for existence of the file by file.exists() or file.access()? On Thu, 12 Jun 2008, Josh wrote:> I'm invoking R in batch mode from a bash script as follows: > > R --no-restore --no-save --vanilla > <$TARGET/$directory/o2sat-$VERSION.R> > $TARGET/$directory/o2sat-$VERSION.Routput > > When R comes across some error in the script however it seems to halt > instead of running subsequent lines in the script: > > Error in file(file, "r") : cannot open the connection > Calls: read.table -> file > In addition: Warning message: > In file(file, "r") : > cannot open file '/datapool/experiments/ois/080502/petri': No such > file or directory > Execution halted > > > How can I get R to continue running the script even if it comes across > errors? Thanks in advance > > ______________________________________________ > 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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595