Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using install.packages with custom temp dir

Tags:

r

cran

devtools

I would like to install a package with a security profile that does not have access to /tmp , but has its own temporary directory, for example /tmp/jeroen. However even though I try to pass the TMPDIR environment variable, it still fails because it tries to use /tmp. Below a toy example using RAppArmor and unixtools (see here for the test profile)

> library(RAppArmor)
> library(unixtools)

> dir.create("/tmp/jeroen")
> set.tempdir("/tmp/jeroen")
> setwd(tempdir());

> aa_change_profile("r-test")
Switching profiles...

> print(tempdir());
[1] "/tmp/jeroen"

> install.packages("plyr", lib="/tmp/jeroen", configure.vars="TMPDIR=/tmp/jeroen")
trying URL 'http://cran.rstudio.com/src/contrib/plyr_1.8.tar.gz'
Content type 'application/x-gzip' length 384462 bytes (375 Kb)
opened URL
==================================================
downloaded 375 Kb

Fatal error: cannot create 'R_TempDir'

The downloaded source packages are in
    ‘/tmp/jeroen/downloaded_packages’

When looking at the kern.log file (which logs security messages), it turns out that the problem is that R CMD INSTALL still tried to use /tmp which was denied:

Jul 24 19:41:34 Jeroen-Antec kernel: [16270.696805] type=1400 audit(1374687694.097:599):
apparmor="DENIED" operation="mkdir" parent=5798 profile="r-test" name="/tmp/RtmpcUOJuQ/"
pid=5802 comm="R" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000

Is there any way I can tell R CMD INSTALL to use /tmp/jeroen instead?

like image 295
Jeroen Ooms Avatar asked Oct 21 '22 04:10

Jeroen Ooms


1 Answers

The correct answer was given by @hadley in the comments: in order to make sure install.packages uses the custom temporary directory, one needs to do

Sys.setenv(TMPDIR="/tmp/jeroen")

in addition to:

configure.vars="TMPDIR=/tmp/jeroen"

This way both the extraction and the installation of the package avoids the system or user default temporary directory.

like image 146
Jeroen Ooms Avatar answered Nov 10 '22 13:11

Jeroen Ooms