是否可以停止`Rscript`清理`tempdir`?

时间:2019-01-07 14:17:47

标签: r logging rscript tmp

我正在通过public class User { private String fullName; private String emailAddress; private String currentAddress; private String phoneNumber; public class User { private String fullName; private String emailAddress; private String currentAddress; private String phoneNumber; public User(String fullName, String emailAddress, String currentAddress, String phoneNumber) { this.fullName = fullName; this.emailAddress = emailAddress; this.currentAddress = currentAddress; this.phoneNumber = phoneNumber; } public String getFullName() { return fullName; } public String getFullName() { return fullName; } public String getFullName() { return fullName; } public String getFullName() { return fullName; } } 和H2O使用R,但是H2O崩溃了。我想查看日志,但是包含R临时目录的R临时目录似乎在R会话结束时(即Rscript完成时)被删除了。

是否可以告诉R / Rscript不要删除它使用的tmp文件夹?

1 个答案:

答案 0 :(得分:1)

为此,一种解决方法是使用on.exit获取临时文件并将其保存在其他目录中。一个示例函数如下所示:

    ranfunction <- function(){
#Get list of files in tempdir
on.exit(templist <- list.files(tempdir(), full.names = T,pattern = "^file") )
#create a new directory for files to go on exit
#use add = T to add to the on.exit call
on.exit(dir.create(dir1 <- file.path("G:","testdir")),add = T  )
#for each file in templist assign it to the new directory   
on.exit(
      lapply(templist,function(x){
      file.create(assign(x, tempfile(tmpdir = dir1) ))})
  ,add=T)

}

ranfunction()

此功能未考虑的一件事是,如果重新运行它-因为新目录dir1已存在,将引发错误。重新运行脚本之前,您必须删除dir1