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).