在R中设置system()的环境变量? [英] set environment variables for system() in R?

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

问题描述

我在Ubuntu中使用R,使用 system()进行系统调用,用于启动Amazon EC2实例,在S3上管理文件等。如果我从命令行启动R一切工作正常。但是,如果我使用Rscript或者ESS从脚本中启动R,则我没有设置环境变量的问题。

I've been using R in Ubuntu to make system calls using system() for things like spinning up Amazon EC2 instances, managing files on S3, etc. If I start R from the command line everything works fine. But if I start R from a script using Rscript, or from ESS, I have issues with environment variables not being set.

认为这是一个问题,我不正确地在Ubuntu中设置环境变量。我认为正确的地方(对于右的一些定义)是将用户环境变量设置在〜/ .bashrc中。这是我设置的东西,如 export EC2_HOME = / home / jd / ec2 ,但是当我从ESS执行R并进行系统调用时,没有运行.bashrc脚本。我已经尝试过Googing,我在Ubuntu中看到很多关于环境变量的解释,例如这一个。我的膝盖反应是在上述线程中尝试每个建议,并且一旦选项工作,就停止给予一个狗屎。但是最后我终于得到了非标准的设置,后来咬我的屁股。

I think this is an issue with me not properly grokking where to set environment variables in Ubuntu. I thought the "right place" (for some definition of "right") was to set user environment variables in ~/.bashrc. This is where I set things like export EC2_HOME=/home/jd/ec2 but when I execute R from ESS and make system calls, the .bashrc script is not being run. I've tried Googing about and I see many an exegesis on environment variables in Ubuntu, such as this one. My knee jerk reaction is to try each recommendation in the aforementioned thread and stop giving a shit as soon as one of the options works. But then I end up with non-standard settings which bite me in the ass later.

那么我应该如何设置环境变量,以便在运行 system()调用时正确设置R?

So how should I set environment variables so that they are properly set when I run a system() call in R?

推荐答案

我觉得你很困惑这个问题。我担心这可能是关于登录shell与非登录shell。看到bash手册页的精细打印...这促使我过去的笨蛋。

I think you are confusing the issue. I fear this may be about login shells versus non-login shells. See the bash manual page for the fine print ... which has driven me bonkers in the past.

这就是说,如果你可以在系统范围内设置环境变量,有几个选项:

That said, if you can set environment variables system-wide, you have a few options:


  • / etc / environment 是一个非常好的地方如果您使用不同的shell

  • 进行登录和非登录shell,那么shell是不可知的,获得完全控制的一种方法是将我的更改为〜/ .local_bashrc

  • 添加。 〜/ .local_bashrc 来自和/或全部

  • /etc/environment is a very good place as it is shell-agnostic should you ever use a different shell
  • for login versus non-login shells, the one way to get complete control that I found suitable was to put my changes into something like ~/.local_bashrc
  • the add . ~/.local_bashrc from and and all of


  • 〜。/ bashrc

  • 〜/ .bash_profile

  • 〜/ .profile` / li>
  • ~./bashrc
  • ~/.bash_profile
  • ~/.profile`

等pp。

您可以使用来自FILE echo Hello(源文件)替换FILE与文件的名称。这显示了从登录开始的shell之间的差异(例如通过 gdm 等),通过 ssh 连接,通过新的 xterm 等终端等等。

You can precede the sourcing with a echo Hello from FILE where you replace FILE with the name of the file. That shows you the difference between shells starting from login (eg via gdm et al), via ssh connection, via new xterm etc terminals and so on.

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

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