[R] Double-banger function names: preferences and suggestions

Steven McKinney smckinney at bccrc.ca
Mon Feb 26 22:27:25 CET 2007


The underscore versus left-arrow 
conundrum has its roots in the evolution
of ASCII during the middle of the last
century. 

Some Teletype machines in the 1970s (when the
S language was being developed) still had a
left arrow, and its ASCII code was used in S
as a one keystroke convenience for the assignment
operator.  The left arrow symbol was then
removed from most keyboards/printers/fontsets
and replaced by the underscore.  Thus the
underscore remained as a one keystroke assignment
operator.


See e.g.

http://www.wps.com/projects/codes/index.html#GRPH


LEFT-ARROW, ?
UNDERSCORE, _

One of the graphical codes, left-arrow mutated to the 
underscore of ASCII-1967. It may have had earlier, 
or other, meanings, but for some early programming 
languages it was "assignment", eg.

      c ? b + a

"C is assigned the sum of B and A".




Steven McKinney

Statistician
Molecular Oncology and Breast Cancer Program
British Columbia Cancer Research Centre

email: smckinney at bccrc.ca

tel: 604-675-8000 x7561

BCCRC
Molecular Oncology
675 West 10th Ave, Floor 4
Vancouver B.C. 
V5Z 1L3
Canada




-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch on behalf of Marc Schwartz
Sent: Sun 2/25/2007 8:28 AM
To: Alberto Vieira Ferreira Monteiro
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Double-banger function names: preferences and suggestions
 
On Sun, 2007-02-25 at 15:56 +0000, Alberto Vieira Ferreira Monteiro
wrote:
> hadley wickham wrote:
> >
> > What do you prefer/recommend for double-banger function names:
> >
> >  1 scale.colour
> >  2 scale_colour
> >  3 scaleColour
> >
> > 1 is more R-like, but conflicts with S3.  2 is a modern version of
> > number 1, but not many packages use it.  Number 3 is more java-like.
> > (I like number 2 best)
> >
> > Any suggestions?
> >
> I always prefer 2, but this would make it non-portable to S-Plus. S-Plus
> has a bug, where _ is the equivalent to <- (why would they do this? I
> prefer to think it's stupidity and not villainy)

That's not a bug. If you search the archives of both the S-PLUS list and
the R lists, you will see highly energized discussion on the use of the
underscore operator.

In R, the use of '_' was allowed for assignment up until version 1.8.0
when:

DEPRECATED & DEFUNCT

    o	The assignment operator `_' has been removed.


and subsequently allowed in names in version 1.9.0 when:

 o	Underscore '_' is now allowed in syntactically valid names, and
	make.names() no longer changes underscores.  Very old code
	that makes use of underscore for assignment may now give
	confusing error messages.


Not to further contribute to the dialog on 'style', but to further
contribute ;-), for those who have coded in the Windows environment (ie.
C, VBA, etc.) the extension of sorts to number 3 is of course "Hungarian
Notation", named after Charles Simonyi, originally at Xerox PARC and
later senior developer/architect at MS. The extension was the inclusion
of the data type prefix, such as fnScaleColour to indicate that this was
a function, with the name using caps to make words more distinct.

And no, I'm not advocating that use...I have been guilty myself of using
variants of 1 and 3, perhaps driven by my circulating caffeine levels as
much as anything else.

HTH,

Marc Schwartz
<Off to go remove 12 inches of snow from the driveway and sidewalk...oy>

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



More information about the R-help mailing list