title: The way UseMethod works in R
body: <pre><code>h &lt;- function(x) {
    x &lt;- 10
    UseMethod("h")
  }
  h.character &lt;- function(x){ paste("char", x)}
  h.numeric &lt;- function(x) { paste("num", x)}
  h("a")
  </code></pre>
  
  <p>The above code will output:</p>
  
  <pre><code>[1] "char a"
  </code></pre>
  
  <p>My deductive reasoning, from the below, says that the output should be "char 10".</p>
  
  <p>According to the documentation of the UseMethod:</p>
  
  <ol>
  <li><p>Find the context for the calling function (the generic): this gives us the unevaluated arguments for the original call.</p></li>
  <li><p>Evaluate the object (usually an argument) to be used for dispatch, and find a method (possibly the default method) or throw an error.</p></li>
  <li><p>Create an environment for evaluating the method and insert special variables (see below) into that environment. Also copy any variables in the environment of the generic that are not formal (or actual) arguments.</p></li>
  <li><p>Fix up the argument list to be the arguments of the call matched to the formals of the method.</p></li>
  </ol>
  
  <p>If I understand it right, in step 2, x would be evaluated to 'a'. But then in step 3, another variable x with the value of 10 is inserted into the environment to execute the method. </p>
  
  <p>Wouldn't that override x to be 10 now? And finally in step 4, arguments are matched to the arguments of the method. So x, which is 10, is now the argument of the method.</p>
  
  <p>What did I get wrong about </p>