Suppose I have two R files: correct.Rand broken.R. What would be the best way to use tryCatchfor error checking?
I currently have
> x = tryCatch(source("broken.R"), error=function(e) e)
> x
<simpleError in source("broken.R"): test.R:2:0: unexpected end of input
1: x = {
^>
> y = tryCatch(source("correct.R"), error=function(e) e)
> y
$value
[1] 5
$visible
[1] FALSE
However, the way I built tryCatchmeans that I have to interrogate the objects xand yto determine if there was an error.
Is there a better way to do this?
The question comes from the doctrine. 100 students upload their R-scripts and I run the scripts. To be nice, I plan to create a simple function that correctly determines whether their sources are functioning properly. He only needs to return TRUE or FALSE.
source
share