Skip to content
Prev 243984 / 398506 Next

How to catch both warnings and errors?

On 2010-12-06, at 01:07 , David Winsemius wrote:

            
Dear David,

many thanks for your help. 
If I call your code with f(-1) and f("a"), I obtain:
$result
[1] NaN

$warning
[1] ""

$error
NULL

=> The problem is that the warning is not given.
Error in log(x) : Non-numeric argument to mathematical function
$result
[1] "Error in log(x) : Non-numeric argument to mathematical function\n"
attr(,"class")
[1] "try-error"

$warning
NULL

$error
NULL

=> The problem is that the error message is printed to the R console instead of suppressed (setting silent = TRUE didn't help either). Further, the $error component is empty (the error message should appear there -- if possible)

Do you know a solution?

Cheers,

Marius