我可以更改 RStudio 保存片段的位置吗?

Can I change where RStudio saves snippets?

我想更改 RStudio 保存存储我的代码片段的 r.snippets 文件的位置。根据 this site,RStudio 应保存到 ~/.R/snippets/r.snippets。我在 Renviron.site 文件中使用 R_USER=C:/Users/JT/R 来设置 ~ 的位置。我认为这段代码有效,因为当我在 RStudio 中检查 ~ 的位置时,我得到:

> path.expand("~")
[1] "C:/Users/JT/R"

但是,当我在 RStudio 中编辑片段时,它会在文件夹 C:\Users\JT\Documents\.R\snippets\ 中创建 r.snippets 文件。我希望 r.snippets 文件保存在文件夹 C:\Users\JT\R\.R\snippets\.

知道我做错了什么吗?谢谢。

在 RStudio 社区网站上,有人提出了同样的问题 Can you change the directory the Rstudio looks for the r.snippets file?

RStudio 员工 kevinushey 的回答非常有帮助:

While that directory isn't currently configurable, you might have luck creating a symbolic link (or, on Windows, a junction point) to re-route the snippets directory to another location.

tom_greenwood,提出问题的用户跟进了 steps he used 的详细信息:

1. Put you existing r.snippets file in the new directory on the shared drive. I called mine 'snippet files'
2. Delete the snippets directory which is inside the .R directory
3. Run cdm as an administrator.
4. Enter the command mklink /D "C:\Users\name.surname\Documents\.R\snippets" "T:\shared directory\snippet files"
5. Restart Rstudio.