title: Dynamic variable names in R regressions
body: <p>Being aware of the danger of using dynamic variable names, I am trying to loop over varios regression models where different variables specifications are choosen. Usually <code>!!rlang::sym()</code> solves this kind of problem for me just fine, but it somehow fails in regressions. A minimal example would be the following:</p>
  
  <pre><code>y= runif(1000) 
  x1 = runif(1000) 
  x2 = runif(1000) 
  
  df2= data.frame(y,x1,x2)
  summary(lm(y ~ x1+x2, data=df2)) ## works
  
  var = "x1"
  summary(lm(y ~ !!rlang::sym(var)) +x2, data=df2) # gives an error
  </code></pre>
  
  <p>My understanding was that <code>!!rlang::sym(var))</code> takes the values of <code>var</code> (namely x1) and puts that in the code in a way that R thinks this is a variable (not a char). BUt I seem to be wrong. Can anyone enlighten me? </p>