Skip to content
Back to formatted view

Raw Message

Message-ID: <F0A60AEC-20FB-4BEF-AD76-177551D9CB37@web.de>
Date: 2010-12-06T10:10:17Z
From: Marius Hofert
Subject: How to catch both warnings and errors?
In-Reply-To: <75D29AEC-CFF8-448D-9717-020FBBC7CFD9@comcast.net>

Hmm... still not quite what I was hoping for... but thanks anyway. 

I would like to have the output in the following form:

> f(1)
$result
[1] 0

$warning
[1] NULL # or ""

$error
[1] NULL # or ""

> f(-1)
$result
[1] NaN

$warning
[1] "Warning in log(-1) : NaNs produced" # or something similar

$error
[1] NULL # or ""

> f("a")
$result
[1] NULL # or NA 

$warning
[1] NULL # or ""

$error
[1] "Error in log("a") : Non-numeric argument to mathematical function"

Has anyone done that before? I think it's quite a natural problem although I could not find a solution online (dealing with *both* warnings *and* errors). 

Cheers,

Marius