title: How to pass the right-hand side of a formula to another formula?
body: <p>I would like to pass the right-hand side of a formula to an R function which then "adds" the left-hand side of the formula and calls <code>gam()</code>. I would like to achieve this without ugly as.formula() constructions etc. </p>
  
  <p>I got stuck in the following minimal example, do you know what went wrong?</p>
  
  <pre><code>require(mgcv)
  set.seed(0) ## set.seed(1)
  gamEx1 &lt;- gamSim(1, n=400, dist="normal", scale=2) ## simulate some data
  str(gamEx1) ## display structure
  
  ## calling gam() and passing the right-hand side of a formula
  gamFitter &lt;- function(formula.RHS, data, ...){
      z &lt;- 2*data$y + data$f0 # some given values
      gam(z ~ formula.RHS, data=data, ...) # call gam()
  }
  
  ## call the function with the right-hand side of a formula
  gamFitter(formula.RHS=~s(x0)+s(x1)+s(x2)+s(x3), data=gamEx1)
  
  Error in model.frame.default(formula = z ~ formula.RHS, data = data,
                               drop.unused.levels = TRUE) :
    invalid type (language) for variable 'formula.RHS'
  </code></pre>