title: Accessing Arbitrary Columns from an R Data Frame using with()
body: <p>Suppose that I have a data frame with a column whose name is stored in a variable. Accessing this column using the variable is easy using bracket notation:</p>
  
  <pre><code>df &lt;- data.frame(A = rep(1, 10), B = rep(2, 10))
  column.name &lt;- 'B'
  
  df[,column.name]
  </code></pre>
  
  <p>But it is not obvious how to access an arbitrary column using a call to <code>with()</code>. The naive approach</p>
  
  <pre><code>with(df, column.name)
  </code></pre>
  
  <p>effectively evaluates <code>column.name</code> in the caller's environment. How can I delay evaluation sufficiently that <code>with()</code> will provide the same results that brackets give?</p>