在Tortoise SVN中设置R环境变量 [英] Setting R environmental variable in Tortoise SVN

查看:544
本文介绍了在Tortoise SVN中设置R环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为 some_functions.R 的文件中具有函数集合,并保存在 C:\ blah1 \ blah2 \ Rcodes \ some_functions.R 的SVN目录中.我有几个使用此代码文件的Rproject.假设在目录 C:\ blah1 \ blah2 \ Rprojects \ project1 中有一个R项目.我可以使用硬编码路径来引用该文件,并且它可以正常工作.

I have a collection of functions in a file called some_functions.R and saved in a SVN directory in C:\blah1\blah2\Rcodes\some_functions.R . I have several Rprojects which uses this code file. Say a R project is available in the directory C:\blah1\blah2\Rprojects\project1. I can use hard coded path to refer the file and it works.

source("C:/blah1/blah2/Rcodes/some_functions.R")'  

但是我想将路径设置为环境变量.

查看如何展开用户和环境变量在Windows R中设置主目录 a>我在RProfile.site文件中添加以下行

Looking at How to unfold user and environment variable in R language? and setting the home directory in windows R I add the following line in the RProfile.site file

Sys.setenv(R_CODE_PATH = "C:/blah1/blah2/Rcodes")

并在project1.Rnw文件中

and in the project1.Rnw file

source("R_CODE_PATH/some_functions.R")

但是项目文件无法读取some_functions.R文件.我尝试了%R_CODE_PATH%,但没有任何运气.

But the project file can not read the some_functions.R file. I tried with %R_CODE_PATH% without any luck.

不确定我在这里缺少什么.任何帮助深表感谢.

Not sure what I'm missing here. Any help is much appreciated.

推荐答案

您可以使用Sys.getenv()检索环境变量.试试:

You retrieve environment variables using Sys.getenv(). Try:

r_code_path <- Sys.getenv("R_CODE_PATH")

然后,例如:

source(paste(r_code_path, "some_functions.R", sep = "/"))

我将使用.Renviron配置文件来定义环境变量.将其放在R命令Sys.getenv("HOME")返回的任何目录中,并包括如下行:

I would use the .Renviron config file to define environment variables. Put it in whatever directory the R command Sys.getenv("HOME") returns and include lines like this:

R_CODE_PATH=C:/blah1/blah2/Rcodes

这篇关于在Tortoise SVN中设置R环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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