title: accessing variable name in function in R
body: <p>I've defined the following function:</p>
  
  <pre><code>plot_test &lt;- function(data) {
    columns &lt;- names(data)
    for (column in columns) {
      p &lt;- ggplot(data, aes(x=get(column), y=cluster))
      p &lt;- p + geom_jitter(position = position_jitter(height = .1, width=0.1))
      show(p)
    }
  }
  </code></pre>
  
  <p>with input data frame:</p>
  
  <pre><code>a &lt;- data.frame(id=c(1,2), cluster=c(3,4))
  </code></pre>
  
  <p>when I run:</p>
  
  <pre><code>plot_test(a)
  </code></pre>
  
  <p>I get the following error message:</p>
  
  <pre><code>Error in get(column) : object 'column' not found
  </code></pre>
  
  <p>I am not scoping the column variable in the for loop appropriately. Any help would be appreciated. Thanks.</p>