title: Function parameter as argument in an R function
body: <p>I am attempting to write a general function to calculate coverage probabilities for interval estimation of Binomial proportions in R. I intend to do this for a variety of confidence interval methods e.g. Wald, Clopper-Pearson, HPD intervals for varying priors.</p>
  
  <p>Ideally, I would like there to be one function, that can take, as an argument, the method that should be used to calculate the interval. My question then: how can I include a function as an argument in another function?</p>
  
  <p>As an example, for the Exact Clopper-Pearson interval I have the following function:</p>
  
  <pre><code># Coverage for Exact interval
  ExactCoverage &lt;- function(n) {
  p &lt;- seq(0,1,.001)
  x &lt;- 0:n
  
  # value of dist
  dist &lt;- sapply(p, dbinom, size=n, x=x)
  
  # interval
  int &lt;- Exact(x,n)
  
  # indicator function
  ind &lt;- sapply(p, function(x) cbind(int[,1] &lt;= x &amp; int[,2] &gt;= x))
  
  list(coverage = apply(ind*dist, 2, sum), p = p)
  }
  </code></pre>
  
  <p>Where Exact(x,n) is just a function to calculate the appropriate interval. I would like to have </p>
  
  <pre><code>Coverage &lt;- function(n, FUN, ...)
  ...
  # interval
  int &lt;- FUN(...)
  </code></pre>
  
  <p>so that I have one function to calculate the coverage probabilities rather than a separate coverage function for each method of interval calculation. Is there a standard way to do this? I have not been able to find an explanation.</p>
  
  <p>Thanks,
  James</p>