我正在通过Rscript和H2O使用R,但是H2O崩溃了。我想查看日志,但当R会话结束时(即Rscript结束时),包含它们的R tempdir似乎被删除了。
可以告诉R/Rscript不要删除它使用的tmp文件夹吗?
发布于 2019-01-08 23:56:14
解决此问题的一种方法是使用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。
https://stackoverflow.com/questions/54076077
复制相似问题