[Rd] ** operator

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu May 15 17:15:35 CEST 2008


I found an entry for the '** operator' in the index of the 1988 Blue Book, 
with a reference to p. 431.  I see nothing about it on p. 431 (or 432), 
but that is the help page for 'Deprecated'.

So I surmise that this was part of a version of S prior to that which 
started life as QPE (with first-class user functions).

It has been in the R tokenizer since at least 1998.

On Thu, 15 May 2008, Prof Brian Ripley wrote:

> On Thu, 15 May 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?
>
> AFAIK it has only ever been used by the parser, which replaces it by ^ in the 
> tokenizer.  I believe it is undocumented in R, but S used to allow it (and 
> may still), so presumably it is for compatibility.
>
> As Duncan Murdoch says, use undocumented features at your own risk.  I've 
> contemplated removing this one at times.
>
> -- 
> 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
>
> ______________________________________________
> 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