[Rd] ** operator

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Thu May 15 16:37:50 CEST 2008


Roger Bivand wrote:
> On Thu, 15 May 2008, Barry Rowlingson wrote:
>
>> Duncan Murdoch wrote:
>>
>>>  It's fairly unlikely to go away, but it's an old undocumented
>>> feature, so
>>>  use at your own risk.  There are lots of other undocumented
>>> features, but
>>>  maybe no others at the lexical level.  Check out src/main/gram.y if
>>> you
>>>  want to search for more at that level, and src/* if you want them
>>> at any
>>>  level.
>>
>>
>> I just had a quick browse in the source and I can't see where "**" is
>> defined. names.c relates ^ to the power operation in arithmetic.c but
>> no sign of "**":
>>
>> ./names.c:{"^",         do_arith,       POWOP,  1,      2,
>> {PP_BINARY2, PREC_POWER,  1}},
>>
>> grepping for POWOP doesn't help.
>>
>>  It's not an operator like '*':
>>>  get("**")
>> Error in get("**") : variable "**" was not found
>>>  get("*")
>> function (e1, e2)  .Primitive("*")
>>
>> and there's no ** in gram.y.
>>
>> searching for 'power' and quoted "**" doesn't help me either.
>> Searching for unquoted ** just produces too much C code to be useful.
>>
>> It's got to be there somewhere!!!
>
> Is there a clue in:
>
>> "^"(5, 2)
> [1] 25
>> "**"(5, 2)
> Error: could not find function "**"
>> 5 ^ 2
> [1] 25
>> 5 ** 2
> [1] 25
>
> that is, it is truly obfuscated and not accessible using contemporary
> interfaces?
Not really, just transcribed during the lexical analysis phase:

    case '*':
        if (nextchar('*'))
            c='^';
        yytext[0] = c;
        yytext[1] = '\0';
        yylval = install(yytext);
        return c;

(There's no "->" function either...)

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-devel mailing list