2

I have multiple workstations where I sync R project code on github. I want to get an alert to commit and push my code in github before closing R studio.

I found ways to get customized alert messages in case of browsers mostly useful in case of jscript, java query coding but I do not find any option for Rstudio .

I do not have remote server access so once I forget to commit my code having access to code on a different workstation is difficult. Hence, I want to customize an alert while closing R Studio and leaving the current workstation.

here are few examples Execute function before refresh

John Coleman
  • 51,337
  • 7
  • 54
  • 119
Soum
  • 63
  • 1
  • 5

1 Answers1

2

Yes. You need to build a function called .Last This is documented on the help page ?q. .Last will be run when you quit. Note that R will exit after .Last has completed unless .Last throws an error, so if you want a chance to go back and save your work, you will probably want to call stop() in your function if you have not saved your work. A simple example might be:

.Last <- function() {
    cat("Did you remember to save to Git?\n")
     flush.console()
    while(TRUE) {
        response <- readline(prompt="Did you save to Git? ")
        if(grepl("Y", response, ignore.case=TRUE)) { 
            cat("OK. Bye\n")
            return() 
        } else {
            if(grepl("N", response, ignore.case=TRUE)) { 
                cat("Better save\n")
                stop() 
            } else {
                cat("Please answer Yes or No\n")
                flush.console() }
        }
    }
}
G5W
  • 36,531
  • 10
  • 47
  • 80