Running script when R Studio shutting down


There seems plenty of ways to run R scripts to clear history etc on R Studio start up, is there any way to automatically run a script to clean history etc from R Studio as it shuts down?

We have slightly paranoid IT Sec people who want to make sure on shared computers that everything is squeaky clean.


In your .Rprofile, you can add

.Last <- function()  cat("\nSo long and thanks for all the fish!\n")