if statement - Testing whether R command has error or not in ifelse command -
if statement - Testing whether R command has error or not in ifelse command -
i want check whether r command has error or not in iflese command. similar next one. wonder how accomplish one. want run next code if there no error in previous r code.
ifelse( test= check r command has error or not , yes = false , no = true ) ifelse( test= log("a") # has error , yes = 3 , no = 1 )
you can utilize trycatch
this:
trycatch({ log(10) 1 }, error=function(e) 3) # [1] 1 trycatch({ log('a') 1 }, error=function(e) 3) # [1] 3
in sec illustration above, first look (which can multi-line, above) throws error, look passed error
argument executed.
r if-statement
Comments
Post a Comment