I'd like to do some cleanup work before the R process is exited by accidently. Is there any api like java's shutdown hook in R ? Thanks
Asked
Active
Viewed 169 times
1
-
1Not quite sure what you mean, but perhaps `?on.exit` is intersting for you – talat Dec 08 '16 at 07:13
-
1`?reg.finalizer` may also be of interest – captainpete Oct 06 '17 at 08:49
1 Answers
0
Defining a .Last function will do the trick.
.Last <- function() {
printf("\n == END of R | %s (runtime %s) ==\n", Sys.time(),format(round(difftime(Sys.time(), .r.start.time), 2)))
}
similarly .First function is called at the start of the script.
Alok
- 3,160
- 3
- 28
- 47
-
it seems .Last doesn't work for me. My scenario is that I am in R interactive session, and then I press ctrl + z to stop the R session. and I want to execute something before exit the R session. – zjffdu Dec 08 '16 at 08:09