This is in one sense a persistent topic across many area of computer
science. Doubling up of characters as in ** as an exponentiation operator is
far from unique. It probably is still being used in other computer languages
as the only way to exponentiate using symbols. Rolf is correct that it may
not be needed and John is correct that it likely is used and removing it,
even with warnings, will likely cause problems.

Given the small number of symbols available in earlier times, including for
example that ASCII has fewer than EBCDIC and far fewer than versions of
UNICODE, it was inevitable that programmers and language developers
preferred short groupings of symbols that often included doublings. Consider
how many complaints have been seed for == versus just = ( and note I have
also seen === and of course others like :=). What about mistakes between
using > versus >> or other doubles like && and ||. Languages can have
autoincrement operators like ++ with a matching -- and so on.Plenty of
mistakes in programs have been caused when you used the wrong one for the
purpose and yet it compiled and ran.

Of course, R does not have all of these. R does allow some monstrosities to
be defined as functions so I can do something like:

Result <- alpha `+-&==` beta

Simply searching for adjacent uses of "**" may pick up perfectly legitimate
places where it is used, including in comments. I note some languages have
comments around blocks of code done by programmers that look like this:

/************************
Comment
************************/

Yes, the extra asterisks are not needed but I have seen lots of code
commented this way for multi-line comments.

And, I note in a language like SCALA, symbols used are dynamic. I can write
code like:

Result = Alpha ****** Beta

The above line only works if you have created a method called "******" so
the code can be invisibly rewritten as:

Result = Alpha.******(Beta)

Obviously, if object Alpha has not defined or inherited such a method, it
fails.

This can be a very powerful way to program but obviously opens the door to
all kinds of problems. But that is true for many ares such as what happens
if you have a function called paste0 and another called pasteo and call the
wrong one.


-----Original Message-----
From: R-help <r-help-boun...@r-project.org> On Behalf Of Sorkin, John
Sent: Tuesday, August 26, 2025 12:24 PM
To: Deepayan Sarkar <deepayan.sar...@gmail.com>; Rolf Turner
<rolftur...@posteo.net>
Cc: r-help@r-project.org
Subject: Re: [R] The "**" exponentiation operator.

Rolf et al.,

While removing the ** syntax may fell attractive, removing it will cause
legacy program to abend. This is not what one wants from a programming
language. It might be better to add code to the parser that produces a
wanting message that the ** syntax is not optimal and should be replaced
with ^, but which allow legacy programs to run, albeit with a warning
message. This will allow old programs to keep running and will prevent
Rolf's fumbling finger from fatal flaws.

Your thoughts?

John


John David Sorkin M.D., Ph.D.
Professor of Medicine, University of Maryland School of Medicine;
Associate Director for Biostatistics and Informatics, Baltimore VA Medical
Center Geriatrics Research, Education, and Clinical Center;
PI Biostatistics and Informatics Core, University of Maryland School of
Medicine Claude D. Pepper Older Americans Independence Center;
Senior Statistician University of Maryland Center for Vascular Research;

Division of Gerontology and Paliative Care,
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
Cell phone 443-418-5382





________________________________________
From: R-help <r-help-boun...@r-project.org> on behalf of Deepayan Sarkar
<deepayan.sar...@gmail.com>
Sent: Tuesday, August 26, 2025 11:55 AM
To: Rolf Turner
Cc: r-help@r-project.org
Subject: Re: [R] The "**" exponentiation operator.

On Tue, 26 Aug 2025 at 11:06, Rolf Turner <rolftur...@posteo.net> wrote:
>
>
>
> On more than one occasion I have got myself into trouble by
> fumble-fingering and typing "**" when I intended to type "*".
> Unfortunately the expression produced is syntactically correct and the
> consequent incorrect results were difficult (for me) to disentangle.
>
> I would be much happier if the "**" operator were simply not allowed,
> and threw an error.   It seems to me that the existence of the "**"
> operator is an archaism, probably deriving from Fortran.
>
> The documentation, obtained from ?Arithmetic, says at one point:
>
> > ** is translated in the parser to ^, but this was undocumented for
> > many years. It appears as an index entry in Becker et al. (1988),
> > pointing to the help for Deprecated but is not actually mentioned on
> > that page. Even though it had been deprecated in S for 20 years, it
> > was still accepted in R in 2008.
>
> It seems still be accepted in R in 2025.
>
> Would there be any mileage in asking R Core to deprecate "**", or
> better still make it defunct?  Can there be any rational basis for
> keeping "**" around?

Not a rational basis perhaps, but when I teach R to our newbie
students who all want to learn Python, I have fun pointing out that **
is the official way to exponentiate in Python, and ^ does something
quite crazy. So keeping ** around in R might make it a tad bit more
welcoming to Pythonistas.

Best,
-Deepayan

> cheers,
>
> Rolf Turner
>
> --
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Stats. Dep't. (secretaries) phone:
>          +64-9-373-7599 ext. 89622
> Home phone: +64-9-480-4619
>
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
https://www.r-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
https://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to