Posts Tagged ‘alarm’

(Almost) Friday Function: alarm

21st April, 2011 2 comments

Last week I decided to start a weekly column detailing an interesting function each Friday, entirely forgetting that I would be on holiday, without internet access (shock horror!), tomorrow. So here’s your column a little early.

The alarm function is something of a novelty, in that all it does is to make an annoying noise when you call it. The only vaguely sensible time that I can think of that you might want to do this is when an error is thrown. Setting this up means overriding the default error handling behaviour, which is surprisingly easy.

options(error = alarm) 
stop("!!!")  # to test the behaviour

For best results, make sure you’ve unplugged your headphones and turn the volume up loud to annoy friends, family and colleagues while debugging.

(To restore the default behaviour, use options(error = NULL).)