title: Is it possible to define a `function` and insert it in `formula` to construct a `model.frame` in R?
body: <p>I was trying to extract a <code>model.frame</code> in R by defining a function to use it in formula as:</p>
  
  <pre><code>library(Formula)
  df &lt;- data.frame(c = LETTERS[1:2], a = c(74, 80), b = c(8, 10))
  soln &lt;- function(x, y){
       A &lt;- matrix(c(1, 1, 1, -2), nrow=2)
       B &lt;- matrix(c(x, y), nrow=2)
       return((as.matrix(solve(A)%*%B))[1,])
  }
  F1 &lt;- Formula::Formula(c ~ . | (soln(a, b)))
  mf &lt;- stats::model.frame(F1, data = df)
  mf
    c  a  b  soln(a, b)
  1 A 74  8  76.000000
  2 B 80 10   8.666667
  </code></pre>
  
  <p>Here <code>mf</code> provides a <code>data.frame</code> that does NOT match the actual value from <code>soln()</code> function. In fact <code>soln(74, 8) = 52</code> and <code>soln(80, 10) = 56.66667</code>, but in <code>mf</code> it is showing <code>76</code> and <code>8.666667</code>. How is this function working in the model formula? Is it possible to define a function to get the correct values in the <code>model.frame</code> this way?</p>