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

Marc Schwartz marc_schwartz at comcast.net
Sun Feb 25 17:28:22 CET 2007


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>



More information about the R-help mailing list