R function for a timer with a beep
To avoid repeating code, you could have used:

done &lt;- FALSE
while(!done){
  done &lt;- round(as.double(difftime(Sys.time(), t0, u = units))) &gt;= interval
}


Note however that a for loop is quite taxing on your CPU. Instead, you should use the friendlier Sys.sleep function. It takes a number of seconds as input:

timer &lt;- function(num_sec) {
   Sys.sleep(num_sec)
   if (require(beepr)) beep(2) else message("DONE!")
}


Notice how I improved your code regarding the use of require, since you had not accounted for the possibility that your user does not have the beepr package installed. If you want to make the beepr package a requirement, then calling library(beepr) is prefered to require(beepr), the blog here https://yihui.name/en/2014/07/library-vs-require/ offers a nice explanation.

If you absolutely want your function to allow to pass "minutes", "days", etc. (though I would stay away from it), you can do:

timer &lt;- function(interval, units = c("secs", "mins", "hours", "days", "weeks")) {
   units &lt;- match.arg(units)
   num_sec &lt;- interval * switch(units, secs = 1, mins = 60, hours = 3600,
                                       days = 86400, weeks = 604800)
   Sys.sleep(num_sec)
   if (require(beepr)) beep(2) else message("DONE!")
}