Skip to content

sum(), min(), max(), prod() vs. named arguments in ...

1 message · Mikael Jagan

#
On 2023-04-15 6:00 am, r-devel-request at r-project.org wrote:
Message-ID: <20230414133800.75383dae-6792 at arachnoid>
Forbidding or warning against tagged arguments other than 'na.rm' would be
quite intrusive, since it is not uncommon to see do.call(sum, <named list>).
That would be much easier to support, as users should be accustomed to that
_not_ working.
str(...) only gives the structure of the first argument matching the dots.
'ExtraArg' doesn't match the dots, as you say, but even if it did, it would
be discarded silently by 'str' there.  Better would be, e.g., str(list(...)).
In both of your examples, just one named "actual" matches the "formal" '...'
in the call to 'NextMethod': the promise 'na.rm' evaluating to FALSE.

Named actuals matching the formal '...' are used to update the original call:

         sum(structure(100, class = 'foo'))
     ==> sum(structure(100, class = 'foo'), na.rm = na.rm)

         sum(structure(100, class = 'foo'), ExtraArg = -1)
     ==> sum(structure(100, class = 'foo'), ExtraArg = -1, na.rm = na.rm)

The new call is evaluated, this time dispatching the internal default method,
giving the results that you observed.

FWIW, help("NextMethod") does warn:

     When a primitive is called as the default method, argument matching may
     not work as described above due to the different semantics of primitives.

Mikael