beepr (former pingr) is on CRAN. It’s easier than ever to make R go beep!
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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:
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">install.packages(<span style="color: #BA2121">"beepr"</span>) library(beepr) beep() </pre></div>
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 🙂
Here is the code:
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">library(audio) library(animation) <span style="color: #408080; font-style: italic"># You would have to change this path to point to a valid wav-file </span> w <span style="color: #666666"><-</span> load.wave(<span style="color: #BA2121">"inst/sounds/microwave_ping_mono.wav"</span>) w <span style="color: #666666"><-</span> w[<span style="color: #666666">1000:7000</span>] <span style="color: #408080; font-style: italic"># Trim both the start and the end of the ping sound</span> plot_frame <span style="color: #666666"><-</span> <span style="color: #008000; font-weight: bold">function</span>(sample_i) { old_par<span style="color: #666666">=</span>par(mar<span style="color: #666666">=</span>rep(<span style="color: #666666">0.1</span>, <span style="color: #666666">4</span>)); plot(w[seq(<span style="color: #666666">1</span>, sample_i)], type<span style="color: #666666">=</span><span style="color: #BA2121">"l"</span>, xaxt<span style="color: #666666">=</span><span style="color: #BA2121">"n"</span>, yaxt<span style="color: #666666">=</span><span style="color: #BA2121">"n"</span>, ylim<span style="color: #666666">=</span>c(<span style="color: #666666">-0.3</span>, <span style="color: #666666">0.3</span>), col<span style="color: #666666">=</span><span style="color: #BA2121">"darkblue"</span>) text(x<span style="color: #666666">=3400</span>, y<span style="color: #666666">=0.2</span>, labels<span style="color: #666666">=</span><span style="color: #BA2121">"beepr (former pingr)"</span>, cex<span style="color: #666666">=1.5</span>) text(x<span style="color: #666666">=3900</span>, y<span style="color: #666666">=-0.2</span>, labels<span style="color: #666666">=</span><span style="color: #BA2121">"- now on CRAN!"</span>, cex<span style="color: #666666">=1.5</span>) par(old_par) } saveGIF(interval <span style="color: #666666">=</span> <span style="color: #666666">0.1</span>, ani.width <span style="color: #666666">=</span> <span style="color: #666666">200</span>, ani.height <span style="color: #666666">=</span> <span style="color: #666666">100</span>, expr <span style="color: #666666">=</span> { <span style="color: #408080; font-style: italic"># The animation</span> <span style="color: #008000; font-weight: bold">for</span>(sample_i <span style="color: #008000; font-weight: bold">in</span> seq(<span style="color: #666666">1</span>, length(w), length.out<span style="color: #666666">=40</span>)) { plot_frame(sample_i) } <span style="color: #408080; font-style: italic"># Just repeating the last image a couple of times...</span> <span style="color: #008000; font-weight: bold">for</span>(i <span style="color: #008000; font-weight: bold">in</span> <span style="color: #666666">1:15</span>) { plot_frame(length(w)) } }) </pre></div>
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.