Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are default values not dispatched with UseMethod?

Tags:

r

Trying to understand why rownames = FALSE is not passed on from Test to Test.list?

Test = function( object , rownames = FALSE , ... )
{
    UseMethod( "Test" )
}

Test.list = function( object , rownames , ... )
{
    browser()
    # rownames is missing!
}

Test( list() )
like image 643
SFun28 Avatar asked Oct 18 '11 00:10

SFun28


1 Answers

Only actual arguments are passed on to the method. Each S3 method can have their own different default values (which would be a very bad design though).

You should strive to have the same parameters with the same defaults as the generic function, and then possibly some extra parameters at the end.

# Bad design, but possible to have defaults be different...
Test.list = function( object , rownames = TRUE , ... )
{
    browser()
    # rownames is TRUE!
}

Test( list() )
like image 165
Tommy Avatar answered Nov 03 '22 08:11

Tommy