2017年12月12日火曜日

Automatic save before quit



.Last <- function() {
  # save.image(file=paste(getwd(),Sys.time(),sep="/"))
  save.image(file=gsub(" ","",paste(getwd(),Sys.time(),sep="/")))
  cat("bye bye...\n")
}
quit("yes")

Backup files are created under the current working directory with the time stamp.



save.image(file=paste(getwd(),format(Sys.time(), "%b%d%X"),sep="/"))

or

save.image(file=gsub(" ","",paste(getwd(),Sys.time(),sep="/"))

Will eliminate unnecessary space in the file names.

> gsub(" ","",paste(getwd(),Sys.time(),sep="/")
+ )
[1] "/Users/honomoto/2017-12-1210:08:23"

Below will improve the readability.

> gsub(" ","",paste(getwd(),gsub(" ","-",Sys.time()),sep="/"))
[1] "/Users/honomoto/R_proj/tmp1/2018-08-14-15:00:34"


format(Sys.time(), "%b%d%X")
[1] "121210時03分53秒"
Sys.setlocale("LC_ALL",'C')
[1] "C/C/C/C/C/ja_JP.UTF-8"
format(Sys.time(), "%b%d%X")
[1] "Dec1210:04:28"

0 件のコメント: