4

I have two functions, f_ that throws an error and f that throws a warning before calling f_.

f_ <- function() stop()
f <- function() {
  warning()
  f_()
}

Since I have a warning before the error, R produces "additionnal warning messages", but the message in this warning is not my f warning but the error produced in f_ called a 2nd time :

> f()
Error in f_() : 
In addition: Warning message:
In f() :
  Error in f_() :

It seems to works as expected if the error is produced in the same function or by a built_in function.

f <- function() {
  warning()
  stop()
}
> f()
Error in f() : 
In addition: Warning message:
In f() : 

Can someone helps me to understand what is happening there ? Thanks for any help. I'm running R version 3.3.2 on x86_64-w64-mingw32 using RStudio.

1

1 Answer 1

2

I think this is caused by the Rstudio error inspector. When encountering an error Rstudio displays the possibility for traceback and debugging. I believe that is the source of the confusion (my own included). The "second" error is simply a feature in Rstudio which assists in debugging as seen below. Note the two buttons on the right allowing you to "show traceback" and "rerun with debug".

In Rstudio enter image description here

As you can see below, if you run R in a terminal, this "additional" error is not there.

In a terminal enter image description here

In your global options in Rstudio, under General tab, you can turn off the use of the debug error handler. You can also do this under Debug -> On Error. Rstudio will then not display the "additional" message.

Edit: Upon investigating a bit further, there is something odd going on though. Below, I tried to make the error and warning message a bit more informative with the following observations:

  • Calling f() many times in a row, it is not entirely clear to me when the error inspector appears and when it does not.
  • When the error inspector does appear, the warning message is not displayed. When the error inspector does not appear, the warning message is displayed.

I do not know anything about Rstudio's internals, but it is quite definitely the error inspector causing these minor issues.

enter image description here

4
  • Strange, yes i'm using Rstudio Oct 10, 2018 at 18:52
  • 1
    To ne the results seem to be identically. Do l miss something?
    – Christoph
    Oct 10, 2018 at 18:59
  • thank you for the error profiling it's really helpful Oct 11, 2018 at 9:03
  • @JulienNavarre Glad I could help. Oct 11, 2018 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.