Skip to content
Back to formatted view

Raw Message

Message-ID: <17ae09c9-7a49-311a-aeec-f8adb1bf5d18@gmail.com>
Date: 2018-08-10T07:10:02Z
From: Duncan Murdoch
Subject: [R-pkg-devel] Calling R's tempdir() from C
In-Reply-To: <f03e7762-0c5a-0289-25c9-0bcacdeb8a02@icrar.org>

On 10/08/2018 12:01 AM, Rodrigo Tobar wrote:
> Dear all,
> 
> I want to create a temporary directory from within my C++ R extension.
> On the other hand, CRAN's policy dictates that one cannot write anything
> outside the boundaries of the session's temporary directory, so I need
> to create it exactly there.
> 
> The R API offers R_tmpnam and R_tmpnam2, both of which require the path
> of the directory where the new name will reside. This can be obtained
> using tempdir() in R, but I couldn't find anything similar in the R API.
> Am I missing anything too obvious?

Why not pass the result of tempdir() in your call from R to your C++ 
function, or in an initialization call for your package?  It won't 
change during a session.

Duncan Murdoch

> 
> I tried out giving a NULL dirname to R_tmpnam{,2}, hoping that even
> though it's not mentioned in the docs, they would internally use the
> session's tmp dir, but this simply crashed. When embedding R one could
> also use the R_TempDir global variable, but this is flagged as
> unofficial R API for extensions. Finally, the only solution I could find
> was to call the tempdir() R function from within my C++ extension. This
> works fine, but it bothers me that there not an equivalent entry point
> in R's API.
> 
> Any pointers would be appreciated. If I'm deeply misunderstanding
> something please also shoot.
> 
> Cheers,
> 
> Rodrigo
> 
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>