title: R Pass formula to dataframe in a function
body: <p>I have a dataframe with column A.</p>
  
  <p>I want to have a function like this:</p>
  
  <pre><code>myFunction &lt;- function(df,term) {
    df = df[,term]
    return(df)
  }
  </code></pre>
  
  <p>so I can do this:</p>
  
  <pre><code>myFunction(mydf,"sqrt('A')"))
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>myFunction(mydf,"log('A')"))
  </code></pre>
  
  <p>I tired modifying the function with the following but didn't work:</p>
  
  <pre><code>df = df[,I(term)]
  df = df[,as.formula(term)]
  </code></pre>
  
  <p>Thanks.</p>