如何阻止 RStudio 创建空的“R"?“/home"中的文件夹每次启动时的目录 [英] How stop RStudio from creating empty "R" folder within "/home" directory at every startup

查看:104
本文介绍了如何阻止 RStudio 创建空的“R"?“/home"中的文件夹每次启动时的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 RStudio 选项中为默认工作目录以及我的第一个(也是唯一一个)项目设置路径后,我想知道为什么 RStudio 不断创建一个名为R"的空文件夹?在我的/家"中每次启动时的目录.

After having set the path for the default working directory as well as my first (and only) project within RStudio options I wonder why RStudio keeps creating an empty folder named "R" within my "/home" directory every time it is started.

有没有我可以删除/编辑(最终创建)的文件来阻止这种烦人的行为,如果有,它在哪里?

Is there any file I could delete/edit (eventually create) to stop this annoying behaviour and if so, where is it located ?

系统:Linux Mint v. 19.3软件:RStudio v. 1.3.959/R 版本 3.4.4

System: Linux Mint v. 19.3 Software: RStudio v. 1.3.959 / R version 3.4.4

提前感谢您的任何提示.

Thanks in advance for any hints.

推荐答案

是的,您可以阻止创建 R 目录 — R 可通过一组环境变量进行配置.

Yes, you can prevent the creation of the R directory — R is configurable via a set of environment variables.

然而,正确设置这些并非易事.第一个问题是许多 R 包对它们安装的 R 版本很敏感.如果您升级 R 并尝试加载现有包,它可能会中断.因此,R 包库路径应特定于 R 版本.

However, setting these correctly isn’t trivial. The first issue is that many R packages are sensitive to the R version they’re installed with. If you upgrade R and try to load the existing package, it may break. Therefore, the R package library path should be specific to the R version.

在集群上,另一个问题是运行在不同架构上的不同集群节点可能会读取相同的库路径;这是罕见的,但它发生了.在这种情况下,编译的 R 包可能需要因架构而异.

On clusters, an additional issue is that the same library path might be read by various cluster nodes that run on different architectures; this is rare, but it happens. In such cases, compiled R packages might need to be different depending on the architecture.

因此,通常 R 库路径需要特定于 R 版本和系统架构.

Consequently, in general the R library path needs to be specific both to the R version and the system architecture.

接下来,即使你配置了一个替代路径,如果它不存在,R 也会默默地忽略它.所以一定要手动创建你配置好的目录.

Next, even if you configure an alternative path R will silently ignore it if it doesn’t exist. So be sure to manually create the directory that you’ve configured.

最后,这个配置放在哪里?一种选择是将其放入 用户环境文件,其路径可以通过环境变量R_ENVIRON_USER指定——默认为$HOME/.Renviron.但这并不理想,因为这意味着用户在调用此文件中的 R: 变量时不能临时覆盖此设置覆盖调用环境.

Lastly, where to put this configuration? One option would be to put it into the user environment file, the path of which can be specified with the environment variable R_ENVIRON_USER — it defaults to $HOME/.Renviron. This isn’t ideal though, because it means the user can’t temporarily override this setting when calling R: variables in this file override the calling environment.

相反,我建议在用户配置文件中设置它(例如 $HOME/.profile).但是,当您使用桌面启动器启动 RStudio 时,不会读取此文件,因此请务必编辑您的 *.desktop 相应的文件.1

Instead, I recommend setting this in the user profile (e.g. $HOME/.profile). However, when you use a desktop launcher to launch your RStudio, this file won’t be read, so be sure to edit your *.desktop file accordingly.1

总而言之,将以下内容添加到您的 $HOME/.profile:

So in sum, add the following to your $HOME/.profile:

export R_LIBS_USER=${XDG_DATA_HOME:-$HOME/.local/share}/R/%p-library/%v

并确保该目录存在:re-source ~/.profile(在当前的shell中启动一个新的shell是不够的),然后执行

And make sure this directory exists: re-source ~/.profile (launching a new shell inside the current one is not enough), and execute

mkdir -p "$(Rscript -e 'cat(Sys.getenv("R_LIBS_USER"))')"

以上使用的是 XDG 基础目录规范,这是 Linux 系统上的事实标准.2 路径使用占位符 %p%v.R 将分别填写系统平台和 R 版本(以 major.minor 形式).

The above is using the XDG base dir specification, which is the de-facto standard on Linux systems.2 The path is using the placeholders %p and %v. R will fill these in with the system platform and the R version (in the form major.minor), respectively.

如果您想使用自定义 R 配置文件(用户配置文件")和/或 R 环境文件,我建议通过配置 R_PROFILE_USER 以相同的方式设置它们的位置R_ENVIRON_USER(因为它们的默认位置再次位于用户主目录中):

If you want to use a custom R configuration file ("user profile") and/or R environment file, I suggest setting their location in the same way, by configuring R_PROFILE_USER and R_ENVIRON_USER (since their default location, once again, is in the user home directory):

export R_PROFILE_USER=${XDG_CONFIG_HOME:-$HOME/.config}/R/rprofile
export R_ENVIRON_USER=${XDG_CONFIG_HOME:-$HOME/.config}/R/renviron


1 我没有 Linux 桌面系统,但我相信将 Env 条目编辑为以下内容应该可以:


1 I don’t have a Linux desktop system but I believe that editing the Env entry to the following should do it:

Exec=env R_LIBS_USER=${XDG_DATA_HOME:-$HOME/.local/share}/R/%p-library/%v /path/to/rstudio

2 其他系统需要不同的处理.在 macOS 上,库位置的规范设置为 $HOME/Library/Application Support/R/library/%v.但是,在 macOS 上为 GUI 应用程序设置环境变量令人沮丧的复杂.

2 Other systems require different handling. On macOS, the canonical setting for the library location would be $HOME/Library/Application Support/R/library/%v. However, setting environment variables on macOS for GUI applications is frustratingly complicated.

在 Windows 上,规范位置是 %LOCALAPPDATA%/R/library/%v.要设置此变量,请在 PowerShell 中使用 [Environment]::SetEnvironmentVariable 或在使用 <代码>cmd.exe,使用setx.

On Windows, the canonical location is %LOCALAPPDATA%/R/library/%v. To set this variable, use [Environment]::SetEnvironmentVariable in PowerShell or, when using cmd.exe, use setx.

这篇关于如何阻止 RStudio 创建空的“R"?“/home"中的文件夹每次启动时的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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