title: Iterate over list of Functions in R
body: <p>I'm currently writing a utility to run a series of test on a set of data. I have the data in a data.frame and would like to run N tests on each row of data. (Apologies if my terminology isn't all there: I've been using R for all of five hours).</p>
  
  <p>In my utility, I would like to split the tests into different files and in the main program, load all those tests and run them once for each data.frame row. Here's what I'm doing to source the relevant files:</p>
  
  <pre><code>file.sources = list.files(pattern="validator-.*.R$")
  sapply(file.sources,source,verbose = TRUE)
  </code></pre>
  
  <p>This works well, and if I do this in each matched file:</p>
  
  <pre><code>b &lt;- function(a) {
    if(grep("^[[:blank:]]*$", a)) {
      return(FALSE)
    } else {
      return(TRUE)
  }
  
  test.functions &lt;- append(test.functions, b)
  </code></pre>
  
  <p>Then I end up with a <code>test.function</code> list which accurately contain all the test functions to run, but this is now where I get stuck. I've tried variations of <code>sapply()</code> and I think <code>do.call()</code> is also relevant in this. This is my current attempt:</p>
  
  <pre><code>process.entry &lt;- function(a) {
    lapply(test.functions,do.call,a)
  }
  sapply(all.data,process.entry)
  </code></pre>
  
  <p>My attempt here was to create a function which takes one row of data as its argument, iterates over <code>test.functions</code> and calls <code>do.call()</code> with the function and row of data as arguments. This doesn't seem to work quite, and the error thrown is:</p>
  
  <pre><code>Error in FUN(X[[i]], ...) : second argument must be a list
  </code></pre>
  
  <p>However, I'm not entirely sure where this error occurs, and quite possibly: there are other, cleaner, ways of doing what I intend!</p>