In R, we can use a file called .Rprofile to do things in R based on a number of triggers. One thing I’ve done is give myself a DIY notification of how many data breaches I’ve been involved in!

First of all, you need a file called .Rprofile that’s stored in your working directory. Some useful resources about .Rprofiles can be found on .Rprofile CRAN docs and an .Rprofile intro.

Now inside that file, you can add a number of functions that are based on a number of events like loading or closing R. I need a .First function for on load and whatever I produce has to be able to print to the console with cat().

With that in mind, instead of showing details, I chose to show the number of breaches I’m in. You can get HIBPwned from CRAN and use it to query the awesome website HaveIBeenPwned.com.

One thing that’s neat about the account_breach() function is that I can query multiple email addresses or user formats to get info. Here is my .Rprofile file that gives me notifications on load for data breaches:

console .Rprofile result
console .Rprofile result
Use your .Rprofile to give you important notifications
Tagged on:             

4 thoughts on “Use your .Rprofile to give you important notifications

  • 24/06/2016 at 00:23
    Permalink

    Cheers for this package. Very neat.

    Just curious why you need this in the .First function? It’s a single call to cat(), so as long as it’s somewhere in .Rprofile it will execute on startup, right? I thought .First was for things that need to be run before anything else (load libraries, etc…) regardless of where it appears in .Rprofile itself. I’m entirely possibly mistaken on that.

    And just quickly, you have a missing http:// in the CRAN link, so it’s defaulting to a local link.

    Reply
    • 24/06/2016 at 09:52
      Permalink

      You are indeed correct that just the cat() will work! Thanks for the heads up on the link 😀

      Reply
  • 25/06/2016 at 06:16
    Permalink

    Nice tip. One small suggestion. Wrap the call in try, since if you don’t have the package installed, starting R will be problematic.

    Reply
    • 25/06/2016 at 12:18
      Permalink

      Adding error handling is a good shout. I upgraded my windows on the weekend and I was having problems with require and library having some differences in libpath behaviours, otherwise I would have included a bootstrap line to install HIBPwned if not available.

      Reply

What do you think?