[R] Does anyone else think this might be worth a warning?!?

Matthew Walker m.g.walker at massey.ac.nz
Tue Aug 21 01:46:34 CEST 2007


That sounds reasonable to me. For calls with more than three arguments
mean.default() would then produce a warning. If there were only two or
three arguments then I think they'd be bound to "trim" and "na.rm" and
so no warning would appear. As Adaikalavan Ramasamy suggested perhaps
mean.default() could be re-defined to:

mean.default <- function (x, ..., trim = 0, na.rm = FALSE)

or is that just not the done thing given that it might break others' code?

Matthew

Felix Andrews wrote:
> I do think this is worth a warning.
> mean.default could do something like
> if (length(list(...)) > 0) warning("extra arguments ignored")
>
> The same could also apply to many other methods of S3 generic
> functions which are forced to include the formal argument `...` in the
> signature but do not use it.
>
> Felix
>
>
> On 8/19/07, Matthew Walker <m.g.walker at massey.ac.nz> wrote:
>   
>> Hi,
>>
>> I was *very* surprised by this little trick for new players: mean() only
>> considers its first argument!
>>
>>  > mean(1,1,2)
>> [1] 1
>>  > mean(2,1,1)
>> [1] 2
>>
>>
>> I found this very different behaviour to max():
>>
>>  > max(1,1,2)
>> [1] 2
>>  > max(2,1,1)
>> [1] 2
>>
>>
>>
>> Perhaps this is the wrong list to ask, but does anyone else think this a
>> little on the interesting side?  Is it not possible to detect a first
>> argument of length one in the presence of other un-named arguments and
>> at least produce a warning?
>>
>>
>> Cheers,
>>
>>
>> Matthew
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>     
>
>
>



More information about the R-help mailing list