Change tempdir() in session (update R_TempDir)

前端 未结 5 861
既然无缘
既然无缘 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:30

    Update: Simon Urbanecks unixtools package has a function to accomplish this. Below the code (for future reference).

    set.tempdir <- function(path) {
      invisible(.Call(C_setTempDir, path.expand(path)))
    }
    

    C code:

    #include 
    #include 
    #include 
    
    SEXP C_setTempDir(SEXP sName) {
        if (TYPEOF(sName) != STRSXP || LENGTH(sName) != 1)
        Rf_error("invalid path");
        R_TempDir = strdup(CHAR(STRING_ELT(sName, 0)));
        return sName;
    }
    

提交回复
热议问题