[R] tempdir() does not respect TMPDIR
Jinsong Zhao
j@zh@o @end|ng |rom ye@h@net
Mon Aug 31 05:06:06 CEST 2020
The solution to this question is to set environmental variable R_ENVIRON
that point to the .Renviron file. I should read the ?Startup more carefully.
Best,
Jinsong
On 2020/8/31 3:45, Henrik Bengtsson wrote:
> Sorry, I should retract my claim that it's too late to set TMPDIR in
> .Renviron. It does indeed work on Linux and R 4.0.2, e.g.
>
> $ cd
> $ mkdir test
> $ cd test
> $ echo "TMPDIR=$PWD" > ./.Renviron
> $ cat ./.Renviron
> TMPDIR=/home/hb/test
> Rscript --no-init-file -e "tempdir()"
> [1] "/home/hb/test/RtmpyH47tc"
>
> Hmm... either this has changed "recently" or I've got it wrong all the
> time. Eitherway, I need to revise the vignette in my 'startup'
> package.
>
> Sorry for the misleading comment.
>
> So, back to your comment about it does *not* work, that is,
> ~/.Renviron is not read, when you double-click on an .RData file. I
> just tried with R 4.0.2 in a Windows 10 VM and I think I can reproduce
> what you're describing.
>
> The problem seems to be that when one launches Rgui via
> double-clicking .RData, the Rgui will only read ./.Renviron, that is,
> the .Renviron file that is located in the same folder as the .RData
> file. It will never load ~/.Renviron (e.g.
> C:/Users\alice/Documents/.Renviron) unless the .RData file is in that
> folder too.
>
> This looks odd to me but it could be that I made another mistake in my
> conclusions above. I let someone else with a less mushy brain take
> over from here.
>
> /Henrik
>
> On Sat, Aug 29, 2020 at 4:31 PM Jinsong Zhao <jszhao using yeah.net> wrote:
>>
>> I read the help page, I don't understand it very well, since I set the
>> environmental variable TMPDIR in .Renviron. What confused me is when
>> double clicking the *.RData to launch R, the tempdir() does not respect
>> the environmental variable TMPDIR, but launch R by double clicking Rgui
>> icon does.
>>
>> Best,
>> Jinsong
>>
>> On 2020/8/30 0:36, Henrik Bengtsson wrote:
>>> It is too late to set TMPDIR in .Renviron. It is one of the
>>> environment variables that has to be set prior to launching R. From
>>> help("tempfile", package = "base"):
>>>
>>> The environment variables TMPDIR, TMP and TEMP are checked in turn and
>>> the first found which points to a writable directory is used: if none
>>> succeeds ‘/tmp’ is used. The path should not contain spaces. **Note
>>> that setting any of these environment variables in the R session has
>>> no effect on tempdir(): the per-session temporary directory is created
>>> before the interpreter is started.**
>>>
>>> /Henrik
>>>
>>> On Sat, Aug 29, 2020 at 6:40 AM Jinsong Zhao <jszhao using yeah.net> wrote:
>>>>
>>>> Hi there,
>>>>
>>>> When I started R by double clicking on Rgui icon (I am on Windows), the
>>>> tempdir() returned the tmpdir in the directory I set in .Renviron. If I
>>>> started R by double clicking on a *.RData file, the tempdir() return the
>>>> tmpdir in the directory setting by Windows system. I don't know whether
>>>> it's designed.
>>>>
>>>> > sessionInfo()
>>>> R version 4.0.2 (2020-06-22)
>>>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>>>> Running under: Windows 10 x64 (build 18363)
>>>> ...
>>>>
>>>> Best,
>>>> Jinsong
More information about the R-help
mailing list