title: How can I make R read my environmental variables?
body: <p>I am running R on EC2 spot instances and I need R to terminate the instance and cancel the spot request once the script has run.</p>
  <p>For that I have set the &quot;Request ID&quot; into an environmental variable in <code>/.bashrc</code> and my plan was to simply call the following code into R once the script is ready</p>
  <pre><code>system(&quot;ec2-cancel-spot-instance-requests $SIR&quot;)
  </code></pre>
  <p>The issue I am having is that R is not &quot;seeing&quot; the same environmental variables I seen when I type <code>env</code> from outside R thus the command is not working.</p>
  <p>I have checked and if I set my environmental variables at <code>/etc/environment</code> R is able to see those variables, but here is the other problem. As those variables are dynamic (the instance ID and the request ID is different each time a spot instance is created), I am running a script to create them in the form of:</p>
  <pre><code>export SIR=`cat /etc/ec2_instance_spot_id.txt`
  </code></pre>
  <p>Where that file contains the dynamic ID</p>
  <p>So, how can I insert &quot;dynamic&quot; environmental variables into <code>/etc/environment</code> ? Or, how can I make R read the environmental variables at <code>/.bashrc</code>?</p>