From jeff.horner at vanderbilt.edu  Fri Sep  1 00:07:32 2006
From: jeff.horner at vanderbilt.edu (Jeffrey Horner)
Date: Thu, 31 Aug 2006 17:07:32 -0500
Subject: [Rd] Overriding InitTempDir
Message-ID: <44F75DA4.6000209@vanderbilt.edu>

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!");
             exit(1);
         }
     }

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

     R_TempDir=tmp;

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

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 
return.

-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner




[Rd] Overriding InitTempDir
Jeffrey Horner