Home > R > (Almost) Friday Function: alarm

(Almost) Friday Function: alarm

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

  1. Kevin
    21st April, 2011 at 17:42 pm

    With more detailed investigation one learns that the function aliases

    > cat(“\a”)

    Which suggests, for those users who like to be verbose, tossing an extra “\a” into a cat command will add an alarm. Useful.

    • 26th April, 2011 at 23:11 pm

      Well spotted, and yes it does. message(“\a”) too.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: