Jason Rupert
2009-May-04 17:27 UTC
[R] Handling Error Thrown After source(...), read.table(...), and readLines(...)
Finally, I'm getting to a point in working with R where I would like to start to add some smart and custom error handling. Specifically, I would like to add custom error handling to my code for source(...), read.table(...), and readLines(...) For example, right now I have the following:> postprocesspath<-c("C:/") > postprocess_scriptname<-c("Bob.R") > fullpostpocessingpath<-paste(postprocesspath, postprocess_scriptname, sep="") > source(fullpostpocessingpath)Error in file(file, "r", encoding = encoding) : cannot open the connection In addition: Warning message: In file(file, "r", encoding = encoding) : cannot open file 'C:/Bob.R': No such file or directory Instead of the error shown above, I would just like to simply have the last line "cannot open file 'C:/Bob.R': No such file or directory" Or, add my own statement to the above, e.g. ########################################################## ########################################################## [[elided Yahoo spam]] ########################################################## ########################################################## I would like to do something similar for read.table(...) and readLines(...). Is such a thing possible? Thanks again.