在 R 中更改临时目录 [英] Changing temporary directory in R

查看:33
本文介绍了在 R 中更改临时目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Windows 虚拟机,并且在其上安装了 R 和 RStudio,我正在尝试更改 R 写入临时文件的目录.

I'm using a Windows virtual machine and I have both R and RStudio installed on it and I'm trying to change the directory where R writes the temporary files.

当我启动 R 时,我尝试更改临时目录,然后关闭 R.当我重新启动 R 并尝试 tempdir() 时,它仍然显示旧目录,好像什么也没发生.但是,如果在尝试更改 RI 中的临时目录后启动 RStudio 而不是重新启动 R,当我在 RStudio 中尝试 tempdir() 时,它会显示我在 R 中设置的新/更新目录.这怎么可能?怎么了?为什么只有 RStudio 响应我更改临时目录而不响应 R,即使我正在更改目录?

When I start R, I try changing the temporary directory and then close R. When I restart R and try tempdir() it still shows the old directory, as if nothing has happened. However, if after attempting to change the temporary directory in R I start RStudio instead of restarting R, when I try tempdir() in RStudio it shows the new/updated directory I set in R. How is this possible? What is happening? Why does only RStudio respond to my changing of the temporary directory but not R, even though that's where I'm changing the directory?

推荐答案

你究竟是如何设置临时目录的??tempdir 中的 R 文档说:

How exactly are you setting the temporary directory? The R documentation in ?tempdir says this:

默认情况下,tmpdir 将是 tempdir() 给出的目录.这将是 R 会话启动时通过以下规则找到的每个会话临时目录的子目录.依次检查环境变量 TMPDIR、TMP 和 TEMP,并使用找到的第一个指向可写目录的变量:如果没有成功,则使用/tmp".路径不应包含空格.请注意,在 R 会话中设置任何这些环境变量对 tempdir() 没有影响:每个会话的临时目录在解释器启动之前创建.

By default, tmpdir will be the directory given by tempdir(). This will be a subdirectory of the per-session temporary directory found by the following rule when the R session is started. 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.

据推测,如果您设置了 TMPDIR 环境变量,R(以及 RStudio)应该做正确的事情.请注意,您必须在 R/RStudio 启动之前进行设置;您可以通过在 ~/.Renviron~/.Rprofile 中设置它来实现这一点.

Presumedly, if you have the TMPDIR environment variable set, R (and hence RStudio) should just do the right thing. Note that you'll have to set before R / RStudio is launched; odds are you can accomplish this by setting it within ~/.Renviron or ~/.Rprofile.

另见:更改临时目录

这篇关于在 R 中更改临时目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆