title: R: function assigned to object producing unexpected results
body: <p><strong>EDIT:</strong> I solved this one on my own. It had nothing to do with the function object assignment, it was that I was assigning the results to a vector "[]" rather then to a list "[[]]"</p>
  
  <p>here's more reading on the subject: <a href="https://stackoverflow.com/questions/1169456/in-r-what-is-the-difference-between-the-and-notations-for-accessing-the">The difference between [] and [[]] notations for accessing the elements of a list or dataframe</a></p>
  
  <p>I'm trying to filter event data. Depending on what I'm looking at I've got to do the filtering different ways. I've got two functions that I use for filtering (I use them throughout my project, in addition to this instance):</p>
  
  <pre><code>drop_columns &lt;- function(x, ...) {
        selectors &lt;- list(...)
        return(x[ , -which(names(x) %in% selectors)])
      }
  
  filter_by_val &lt;- function(x, col, ...) {
        return(x[ which(x[, col] %in% ...), ])
      }
  </code></pre>
  
  <p>Here's the function that choses which function does the filtering, and then executes it. Note that I'm assigning the function to an object called "filter_method":</p>
  
  <pre><code>filter_playtime_data &lt;- function (key_list, data) {
    filter_method &lt;- NULL
    out_list &lt;- list()
  
    if(key_list$kind == "games") {
      filter_method &lt;- function(key_list) {
        drop_columns(filter_by_val(data, "GameTitle", key_list), "X")
      }
    } else if (key_list$kind == "skills") {
      filter_method &lt;- function(key_list) {
        filter_by_val(data, "Skill", key_list)
      }
    }
    # Separate data with keys
    out_list["ELA"] &lt;- filter_method(key_list[["ELA"]])
    out_list["MATH"] &lt;- filter_method(key_list[["MATH"]])
    out_list["SCI"] &lt;- filter_method(key_list[["SCI"]])
  
    return (out_list)
  }
  </code></pre>
  
  <p>I'm trying to filter data based on "skills" (ie. using filter_by_val) and it's not working as expected. I'm feeding in a data.frame and I'm expecting a data.frame to come out, but instead I'm getting a list of indexes, as if the function is only returning this part of my function: -which(names(x) %in% selectors)</p>
  
  <p>When I run this is the debug browser -- ie. filter_method(key_list[["ELA"]]) -- it works as expected, I get the data frame. But the values held in my output list: out_list[[ELA]] is the list of indexes. Any idea what's happening?</p>