title: Unlisting a list of functions in R
body: <p>I have a list which at least one of the elements is a function: I would like to unlist it. All the functions are somehow related and would like to obtain one function that takes in all the parameters used and outputs the specified results:</p>
  
  <pre><code>f=c(a=function(x,y)x+y+2*x^2,b=function(m)m*exp(m),d=function(x,m)x^2+2*x*m)
  f
  $a
  function (x, y) 
  x + y + 2*x^2
  
  $b
  function (m) 
  m * exp(m)
  
  $d
  function (x, m) 
  x^2 + 2 * x * m
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>g = function(x) c(x[1] + x[2] + 2*x[1]^2, x[3] * exp(x[3]), x[1]^2+2*x[1]*x[3])
  </code></pre>
  
  <p>Can be a function of anything not necessarily x. If  Possible, Base R solution is preferred: (will take other packages too)</p>
  
  <p>My trial:</p>
  
  <pre><code>`unlist(f)` :this fails
  f=sub(",.*","",deparse(f)[-1]);f[length(f)]=sub(")$","",f[length(f)])
   f
  [1] "x + y"           "m * exp(m)"      "x^2 + 2 * x * m"
  </code></pre>
  
  <p>Thank you</p>