Change tempdir() in session (update R_TempDir)

前端 未结 5 835
既然无缘
既然无缘 2021-01-01 03:16

I am looking for a way to change the tempdir() location after an R session has started. I think it would be required to update the C level global variable

5条回答
  •  迷失自我
    2021-01-01 03:49

    It's awfully cheesy, but you could just mask base::tempdir by saying

    tempdir <- function() { "[desired temp dir here]" }
    

    Then you'd be OK as long as you weren't using code that (implicitly or explicitly) looked in the base namespace before the global environment ...

    I really don't see any other way to do this, since it's set at initialization time and not altered thereafter. In other words, Sys.setenv(TMPDIR="/home/bolker/R") doesn't work -- it's too late (as you probably know).

    If tempdir() were less hard-coded it would be a lot easier ... I don't really understand the design criteria here (or, less charitably, whether there were carefully thought-out design criteria ...). (I feel similarly grumpy about the hard-coding/design of .libPaths(), which is similar ... no way to change things once you're in a running R session.)

提交回复
热议问题