[Rd] Is it possible to retrieve the last error? (not error *message*)

Richard Cotton richierocks at gmail.com
Thu May 5 08:59:40 CEST 2016


I wondered the same thing a few days ago.

https://stackoverflow.com/questions/36966036/how-to-get-the-last-error

The here's the solution from that discussion:

get_last_error <- function()
{
  tr <- .traceback()
  if(length(tr) == 0)
  {
    return(NULL)
  }
  tryCatch(eval(parse(text = tr[[1]])), error = identity)
}

Note that it uses .traceback() from R 3.3.0; you'll have to use
baseenv()$.Traceback with earlier version of R.

On 4 May 2016 at 22:41, Henrik Bengtsson <henrik.bengtsson at gmail.com> wrote:
> Hi,
>
> at the R prompt, is it possible to retrieve the last error (as in
> condition object of class "error")?
>
> I'm not asking for geterrmessage(), which only returns the error
> message (as a character string).  I'm basically looking for a
> .Last.error or .Last.condition, analogously to .Last.value for values,
> which can be used when it is "too late" (not possible) to go back an
> use try()/tryCatch().
>
> Thanks,
>
> Henrik
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Regards,
Richie

Learning R
4dpiecharts.com



More information about the R-devel mailing list