Publishable Stuff

Rasmus Bååth's Blog


beepr (former pingr) is on CRAN. It’s easier than ever to make R go beep!

2014-06-29

Even though I said it would never happen, my silly package with the sole purpose of playing notification sounds is now on CRAN. Big thanks to the CRAN maintainers for their patience! For instant gratification run the following in R to install beepr and make R produce a notification sound:

install.packages("beepr")
library(beepr)
beep()

This package was previously called pingr and included a ping() function. By request from the CRAN maintainers it has been renamed in order to not be confused with the Unix tool ping. Consequently it is now called beepr and includes a beep() function instead. Other things that have changed since the original announcement is that it is now possible to play a custom wav-file by running beep("path/to/my_sound.wav") and that a facsimile of the Facebook notification sound has been added and which can be played by running beep("facebook") (thanks Romain Francois for the suggestion!).

Bonus Animation of a “Ping”

For fun I made a little animation of the actual “ping” sound that plays when you run beep() using the audio package and the animation package. Sure, the function is now called beep but I still like the original sound :)

Beepr animation

Here is the code:

library(audio)
library(animation)
 # You would have to change this path to point to a valid wav-file 
w <- load.wave("inst/sounds/microwave_ping_mono.wav")
w <- w[1000:7000] # Trim both the start and the end of the ping sound

plot_frame <- function(sample_i) {
  old_par=par(mar=rep(0.1, 4)); 
  plot(w[seq(1, sample_i)], type="l", xaxt="n", yaxt="n", ylim=c(-0.3, 0.3), col="darkblue")
  text(x=3400, y=0.2, labels="beepr (former pingr)", cex=1.5)
  text(x=3900, y=-0.2, labels="- now on CRAN!", cex=1.5)
  par(old_par)
}

saveGIF(interval = 0.1, ani.width = 200, ani.height = 100, expr = {
  # The animation
  for(sample_i in seq(1, length(w), length.out=40)) {
    plot_frame(sample_i)
  }
  # Just repeating the last image a couple of times...
  for(i in 1:15) {
    plot_frame(length(w))
  }
})
Posted by Rasmus Bååth | 2014-06-29 | Tags: R