Play Sound at End of R Script (2 Examples) | beep Function
This tutorial illustrates how to make a sound at the end of a code in the R programming language.
Table of contents:
- Example 1: Make Beep at End of Script
- Example 2: Different Sound Options
- Video, Further Resources & Summary
Let’s get started!
Example 1: Make Beep at End of Script
If we want to make a beep at the end of an R program, we can use the beepr package. First, we need to install and load the package:
install.packages("beepr") # Install beepr package library(beepr) # Load beepr package
The beepr package contains the beep() function. We can apply the beep function with its default specifications as follows:
beep() # Default beep
If you run the previous R syntax, your computer will return a beep sound.
Example 2: Different Sound Options
The beep function provides several different sounds that we can play at the end or in between your R code. We simply have to specify the sound argument within the beep function to a specific number. Have a look at the R help documentation for the beep command to get more information on the different sounds.
For instance, we can play a treasure sound by specifying the sound option to be equal to 5:
beep(sound = 5) # Adjust sound
Video, Further Resources & Summary
In case you need more information on the R syntax of this tutorial, you might watch the following video which I have published on my YouTube channel. I’m explaining the contents of this article in the video:
The YouTube video will be added soon.
In addition, you could have a look at the other tutorials of this website. I have published numerous tutorials already.
In this tutorial you learned how to make some noise in R. If you have any additional questions, let me know in the comments.