是否有可能停止`Rscript`清理其`tempdir`? [英] Is it possible to stop `Rscript` cleaning up its `tempdir`?

查看:107
本文介绍了是否有可能停止`Rscript`清理其`tempdir`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Rscript和H2O使用R,但是H2O崩溃了.我想查看日志,但是包含R临时目录的R临时目录似乎在R会话结束时(即Rscript完成时)被删除了.

I'm using R, via Rscript and H2O, but H2O is crashing. I want to review the logs, but the R tempdir that contains them seem to be removed when the R session ends (i.e. when the Rscript finishes).

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

Is it possible to tell R/Rscript not to remove the tmp folder it uses?

推荐答案

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

A work around for this would be to use on.exit to get the temporary files and save them in a different directory. An example function would be like this:

    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.

One thing this function does not take into account is that if you rerun it - it will throw an error because the new directory dir1 already exits. You would have to delete dir1 before re-running the script.

这篇关于是否有可能停止`Rscript`清理其`tempdir`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆