Agreed, that's even better, e.g.

    Error in 1 * "a" : character argument not allowed for arithmetic
operator *

For some reason (does anyone know the rationale?), in the case of factors,
you don't get an error, but a more explicit warning and an NA result:

> 2*factor(3)
[1] NA
Warning message:
In Ops.factor(2, factor(3)) : * not meaningful for factors

This seems hazardous, especially since the user has to be sophisticated
enough to know about options(warn=2) to get a traceback for this.

As for data frames, arithmetic operators seem to work if all the values are
numeric:

> 2*data.frame(a=1)
  a
1 2

It's a hard problem to make useful error messages for beginning users....

            -s


On Mon, Jun 1, 2009 at 4:34 AM, Patrick Burns <pburns@pburns.seanet.com>wrote:

> I thought Stavros' suggestion was going
> to be to have the error message say what
> type of offending object was found.  If
> the message said that a list of class
> 'data.frame' was found (probably the leading
> case), then that would be much more helpful.
>
> Patrick Burns
> patrick@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of "The R Inferno" and "A Guide for the Unwilling S User")
>
> Stavros Macrakis wrote:
>
>> On Sun, May 31, 2009 at 6:10 PM, jim holtman <jholtman@gmail.com> wrote:
>>
>>  Message is very clear:
>>>
>>>  1 * 'a'
>>>>
>>> Error in 1 * "a" : non-numeric argument to binary operator
>>>
>>
>>
>> Though the user should have been able to figure this out, perhaps the
>> error
>> message could be improved? After all, it is not the fact that the operator
>> is *binary* that implies that its argument must be numeric, but that it is
>> *arithmetic*. The binary operator %in%, for example, takes non-numeric
>> arguments.
>>
>> Suggested replacement error message:
>>
>>     non-numeric argument to arithmetic operator
>>
>>               -s
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@r-project.org 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.
>>
>>

	[[alternative HTML version deleted]]


