Overlapping R Incomplete Error Messages

When a call exists from several lines, the potential error includes only the first line match.call (), leading to some lost information and an incomplete sentence. A simple example:

#proper error message: runif(n=1, k=5) #incomplete error message: runif(n=1, k={5}) 

What would be the way to make R turn on the full call of the error message (perhaps by dropping a few lines or so)? What interests me most is the use of this tryCatch parameter.

+4
source share
1 answer

I tried to investigate the error object in tryCatch settings using:

 tryCatch( runif(n=1,k={5}), error = function(e) recover() ) 

And then they chose the 4th environment ( value[[3]](cond) ) to study e .

I noticed that e$call was:

 Browse[1]> e$call runif(n = 1, k = { 5 }) 

So it seems that the error message just uses this first line.

You can collapse all lines along with:

 Browse[1]> paste(deparse(e$call),collapse='') [1] "runif(n = 1, k = { 5})" 

So you can try something like:

 tryCatch( runif(n=1,k={5}), error = function(e) { cat(sprintf('Error in %s: %s\n', paste(deparse(e$call),collapse=''), e$message)) } ) 

But this does not fix the error message itself, just a call leading to it:

Error in runif (n = 1, k = {5}): unused argument (s) (k = {

So, "Error in xxx" is complete, but "unused argument (x) xxx" is still missing. This is the beginning, but not so.

I'm not sure how to improve this (and I am also interested in knowing if this is possible).

+3
source

Source: https://habr.com/ru/post/1398751/


All Articles