R/notify.R

Defines functions notify

Documented in notify

#' Notify when a function was executed
#' 
#' @param msg Message you want to get in the notification. By default: Operation complete
#' @param playSound play sound. Default value: TRUE
#' @examples 
#' \dontrun{
#' notify("Jestem hakerem OSX")
#' }

notify <- function(msg = "Operation complete", playSound = T) {
  
  in.osx <- (Sys.info()['sysname'] == "Darwin")
  in.rstudio <- (Sys.getenv("RSTUDIO") == "1")
  in.rgui <- (Sys.getenv("R_GUI_APP_REVISION") != "")
  
  if (in.rstudio) { # hack to see if running in RStudio
    title <- "RStudio"
    sender <- activate <- "org.rstudio.RStudio"
  }
  
  if (in.rgui) { # running in R GUI app?
    title <- "R GUI"
    sender <- activate <- "org.R-project.R"
  }
  
  # if running in RStudio or R GUI app use NotificationCenter otherwise use message()
  if ((in.rstudio | in.rgui) & in.osx) {
    system(paste0('osascript -e \'display notification "', msg ,'" with title "', title , '"\''))
  } else {
    message(msg)      
  }
  
  if (playSound) {
    beepr::beep(3)
  }
  
}
AMUFacultyOfEnglish/ENRanalytics documentation built on May 5, 2019, 11:36 a.m.