Skip to content

help page of warnings()

4 messages · Scott Kostyshak, Elad Zippory, Gabriel Becker +1 more

#
On Sat, Dec 28, 2013 at 11:19 PM, Elad Zippory <elad.zippory at gmail.com> wrote:
Hi Elad,

Please keep the conversation on the list unless there is a reason for
it to be private, in which case please say so. This way everyone can
participate (and more importantly can correct my errors).
In some cases environments can be thought of like lists. As for how
name look-up goes, yes it takes some studying to learn about that.
This is a great programming strategy. You might be interested in one
of my favorite recommendations: treat warnings like errors.

options(warn = 2) # asks R to treat warnings as errors. See ?options

As far as knowing more precisely where something went wrong (where not
in the sense of what line of code, but in which function), consider
using the traceback function. Or, in addition to the above options
command, you might like:

options(error = recover) # asks R to enter the debugger when there is an error

and because warnings are now errors, it also enters the debugger for
warnings. This way you can poke around where the warning occurred.
I still don't see a need to manually access last.warning for the
situation you described.
Thank you for giving more details on what you're trying to accomplish.

Scott


--
Scott Kostyshak
Economics PhD Candidate
Princeton University
#
I've also written a little about it at
http://adv-r.had.co.nz/Exceptions-Debugging.html#condition-handling.

But I think the main problem is assuming that rm(list=ls()) "resets"
back to a clean state.  Apart from the last warning, there are many
other things that this command will not clean up. You're much better
off getting into the habit of restarting R. In Rstudio, this is
particularly convenient because there's a keyboard shortcut (cmd +
shift + F10).

Hadley