title: setting environment variables programmatically
body: <p>In R, I can set environment variables "manually", for example:</p>
  
  <pre><code>Sys.setenv(TODAY = "Friday")
  </code></pre>
  
  <p>But what if the environment variable name and value are stored in R objects?</p>
  
  <pre><code>var.name  &lt;- "TODAY"
  var.value &lt;- "Friday"
  </code></pre>
  
  <p>I wrote this:</p>
  
  <pre><code>expr &lt;- paste("Sys.setenv(", var.name, " = '", var.value, "')", sep = "")
  expr
  # [1] "Sys.setenv(TODAY = 'Friday')"
  eval(parse(text = expr))
  </code></pre>
  
  <p>which does work:</p>
  
  <pre><code>Sys.getenv("TODAY")
  # 1] "Friday"
  </code></pre>
  
  <p>but I find it quite ugly. Is there a better way? Thank you.</p>