title: How to set an S4 method for 2+ classes?
body: <p>I would like to set a method for to 2+ classes, and also enable to pass additional argument.</p>
  <p>The 2 classes :</p>
  <pre><code># Classes
  methods::setClass(
    Class = &quot;A&quot;,
    slots = list(
      x = &quot;character&quot;
    )
  )
  methods::setClass(
    Class = &quot;B&quot;,
    slots = list(
      x = &quot;character&quot;
    )
  )
  </code></pre>
  <p>The method dispatch should be done only for one object (the <code>object</code> argument, which is set as the <code>signature</code> of the generic). The Generic :</p>
  <pre><code># Generic
  methods::setGeneric(
    &quot;method1&quot;,
    def = function(object, additionalArg) base::standardGeneric(&quot;method1&quot;),
    signature = &quot;object&quot;
  )
  </code></pre>
  <p>The method should make use of the object slot, and also the <code>additionalArg</code> if it is passed. The Method :</p>
  <pre><code># Method
  methods::setMethod(
    &quot;method1&quot;,
    signature = c(
      &quot;A&quot;,
      &quot;B&quot;
    ),
    definition = function(object, additionalArg = NULL) {
      print(glue::glue(&quot;Object slot : {object@x}&quot;))
      if (!is.null(additionalArg)) {
        print(glue::glue(&quot;Additional argument : {additionalArg}&quot;))
      }
    }
  )
  </code></pre>
  <p>However, the <code>setMethod</code> fails, even though the signature is set to the <code>object</code> argument, and both the generic and the method implementation for objects of class <code>A</code> and <code>B</code> contain the <code>object</code> and <code>additionalArg</code> arguments.</p>
  <p>The error :</p>
  <pre><code>Error in matchSignature(signature, fdef) : 
    more elements in the method signature (2) than in the generic signature (1) for function ‘method1’
  </code></pre>
  <p>Edit:
  This happens also with the generic and the method having only &quot;object&quot; as argument, so it is not due to having more than 1 argument.</p>