[R] Logging and writing error messages to a dataframe

Abhinaba Roy abhinabaroy09 at gmail.com
Sat Sep 20 08:46:22 CEST 2014


Hi R-helpers,

I intend to record the errors in my R code while calling functions in a
dataframe (ERR_LOG, say). I want to use 'try' to identify errors while
calling a function,if any.The dataframe(ERR_LOG) will have the following
columns :

Time : The time at which the function was called (Sys.time)
Loc : For which function call was this error recorded (name of the function)
Desc : Description of the error which R throws at us (Error message in R)

Example :

First I would like to initialize a blank dataframe 'ERR_LOG' with these
columns

Then write the function
f <- function(a){
  x <- a*100
  return(x)
}

Now I put the output of the call to 'f' in 'chk'
chk <- try(f())

The above call gives the error 'Error in a * 100 : 'a' is missing'
(description of the error)

Check
if(inherits(chk,'try-error'))
{then I want to populate ERR_LOG and stop the code execution}

How can this be done in R?

	[[alternative HTML version deleted]]



More information about the R-help mailing list