avriis
avriis

Reputation: 1681

Crash of debugging browser in R/Rstudio when called from inside do.call

In line with this question, the debugger browser does not show me where it has stopped when it is called from within a do.call statement. First it prints all the arguments to the console and then generally the browser is unresponsive leaving no other option than to force quit RStudio. Does anyone have experience with anything equivalent and can point to any fixes?

This also seems to describe a similar issue.

Upvotes: 4

Views: 628

Answers (1)

Patrick
Patrick

Reputation: 702

This is likely occurring because you have passed some dataset to a function called using do.call. R's default behavior when an error occurs is to enter debugging mode and print the entire function call for context. However, because do.call deparses each argument before calling the function, this can result in a very long statement, causing R to hang.

To limit the length of the call returned when entering browser() model for debugging, you can set the maximum deparse length:

options(deparse.max.lines = 10)

As of R 4.0, you can limit the length of the function call printed when entering debugging mode without changing other uses of deparse() by setting option traceback.max.lines:

options(traceback.max.lines = 10)

This should prevent the hangs caused by printing deparsed function calls when debugging within functions called by do.call.

A bug has been identified with Rstudio that causes it to hang even when these options are set. You may be able to debug this code within the R console or using other tools.

Upvotes: 1

Related Questions