title: passing arguments to function with a view to plotting with ggplot stat_function
body: <p>I have a function and a list of arguments.</p>
  
  <pre><code>F &lt;- function(a,b,...) {a^b+b/a}
  L &lt;- list("a" = 5, "b" = 2, "c" = 0)
  </code></pre>
  
  <p>I want to replace one of the arguments ("a", "b" or "c") with an unknown x (or "x") and plot with ggplot's stat_function.</p>
  
  <p>These computations are part of a shiny app, where the user will 1) select a parameter from a drop-down list, say "a", to be the unknown, and 2) use sliders to select values of the other parameters. The numbers 5, 2, 0 in L are the default parameter values, to be used before user interaction. There are several such functions. Here the list of parameters L has an element not used in F.</p>
  
  <p>I've been stuck on this for so long that I can't think straight anymore. Of the many things I've tried, here's one:</p>
  
  <pre><code># select a parameter to vary:
  Y &lt;- "a"
  f1 &lt;- function(f = F, l = L, y = Y, x, ...){
    l[y] &lt;- x # replace "a" with x
    do.call(f, l, ...)
  }
  
  # make a stat_function ggplot:
  library("ggplot2")
  df &lt;- data.frame(x = c(0,10))
  p &lt;- ggplot(df, aes(x))
  p &lt;- p + stat_function(fun = f1)
  print(p)
  </code></pre>
  
  <p>This returns the following error:</p>
  
  <pre><code>Error in (function (f = F, l = L, y = Y, x, ...)  : 
    argument "x" is missing, with no default
  Error in as.environment(where) : 'where' is missing
  </code></pre>
  
  <p>I have tried several variants, including: setting l[y] &lt;- "x" and using aes_string instead of aes. I have also tried backquotes around x. I have read through the documentation about environments, so I've tried defining an environment, wrapping x and just about everything around eval or quote. I've even tried voodoo. I've lost count of how many hours I've spent on this. A suggestion to read the manual or a hint without an explanation will kill me. 8-)  If my question is unclear, please let me know and I will clarify. Thanks!</p>