How to write generic function with two inputs? : <p>I am a newbee in programming, and I run into an issue with R about generic function: how to write it when there are multiple inputs?</p>

<p>For an easy example, for dataset and function</p>

<pre class="lang-r prettyprint-override"><code>z &lt;- c(2,3,4,5,8)
calc.simp &lt;- function(a,x){a*x+8}
# Test the function:
calc.simp(x=z,a=3)
[1] 14 17 20 23 32
</code></pre>

<p>Now I change the class of z:
class(z) &lt;- 'simp'
How should I write the generic function 'calc' as there are two inputs?
My attempts and errors are below:</p>

<pre class="lang-r prettyprint-override"><code>calc &lt;- function(x) UseMethod('calc',x)
calc(x=z)
Error in calc.simp(x = z) : argument "a" is missing, with no default
</code></pre>

<p>And</p>

<pre class="lang-r prettyprint-override"><code>calc &lt;- function(x,y) UseMethod('calc',x,y)
Error in UseMethod("calc", x, y) : unused argument (y)
</code></pre>

<p>My confusion might be a fundamental one as I am just a beginner. Please help! Thank you very much!</p>
