[Rd] Overriding InitTempDir

Jeffrey Horner jeff.horner at vanderbilt.edu
Fri Sep 1 00:07:32 CEST 2006

For embedded projects, one may want to eliminate the per-session temp 
directory created by InitTempDir() and just use a system-specific temp 
directory. Here's my solution:

extern char *R_TempDir;

void my_InitTempDir()
     char *tmp;

     if (R_TempDir){
         if (rmdir(R_TempDir) != 0){
             perror("Fatal Error: could not remove R's TempDir!");

     tmp = getenv("TMPDIR");
     if (tmp == NULL) {
         tmp = getenv("TMP");
             if (tmp == NULL) {
                 tmp = getenv("TEMP");
                 if (tmp == NULL)
                     tmp = "/tmp";


     if (setenv("R_SESSION_TMPDIR",tmp,1) != 0){
         perror("Fatal Error: couldn't set/replace R_SESSION_TMPDIR!");

This function is called after Rf_initEmbeddedR; it's seems like a hack 
but it works. Does anyone have other solutions?

Maybe InitTempDir could check if R_TempDir was not NULL and then just 


More information about the R-devel mailing list