Skip to content

log2(quote(1:10)) evaluates the quoted 1:10, log() does not

3 messages · William Dunlap, Brian Ripley

#
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.

  > 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
1 day later
#
On Wed, 10 Mar 2010, William Dunlap wrote:

            
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().

  
    
2 days later
#
On Fri, 12 Mar 2010, Prof Brian Ripley wrote:

            
And that does not work, due to S4 dispatch issues in package Rmpfr.
So I have done that.