title: How to use with/within inside a function?
body: <p>I'm struggling to understand why does this doesn't work.</p>
  
  <pre><code>df &lt;- data.frame(a=1:10, b=1:10)
  
  foo &lt;- function(obj, col) {
     with(obj, ls())
     with(obj, print(col))
  }
  foo(df, a)
  </code></pre>
  
  <blockquote>
    <p>[1] "a" "b"</p>
    
    <p>Error in print(col) : object 'a' not found</p>
  </blockquote>
  
  <p>If this does work:</p>
  
  <pre><code>with(df, print(a))
  </code></pre>