[Rd] log2(quote(1:10)) evaluates the quoted 1:10, log() does not
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Mar 12 08:27:34 CET 2010
On Wed, 10 Mar 2010, William Dunlap wrote:
> This is very minor, but shouldn't log2(quote(1:10))
> throw an error,the same as log() and other math functions
> do? It looks like log2 and log10 evaluate a call object
> instead of throwing a non-numeric-argument error. They
> do object to non-call language objects, like expressions.
Yes, but the reason is complex. log2 and log10 first look for methods
for themselves, then for log, and the method dispatch code evaluates
the argument -- so it gets done twice. And because of some of the
peculiarities of the internal S4 dispatch code, it was hard enough to
get to work at all.
The simplest solution seems to be to make log2() and log10() special
primitives (as log is): the alternative is to duplicate a version of
the logb() code in log2() and log10().
>
> > log2(quote(1:10))
> [1] 0.000000 1.000000 1.584963 2.000000 2.321928 2.584963
> [7] 2.807355 3.000000 3.169925 3.321928
> > log(quote(1:10))
> Error in log(quote(1:10)) : Non-numeric argument to mathematical
> function
> > sqrt(quote(1:10))
> Error in sqrt(quote(1:10)) :
> Non-numeric argument to mathematical function
> > quote(1:10) ^ 2
> Error in quote(1:10)^2 : non-numeric argument to binary operator
> > 2 ^ quote(1:10)
> Error in 2^quote(1:10) : non-numeric argument to binary operator
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list