[R] the underscore ("_") in variable name

BXC (Bendix Carstensen) BXC at novo.dk
Mon Oct 2 11:56:40 CEST 2000


> -----Original Message-----
> From: Bill Venables [mailto:Bill.Venables at cmis.csiro.au]
> Sent: 2. oktober 2000 08:08
> To: mohd zamri
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] the underscore ("_") in variable name
> 
> 
> At 14:35 02/10/00 +0800, mohd zamri wrote:
> >new to R and starting to learn to program R. The underscore 
> ("_") did some
> >suprising result. e.g
> >
> >> c <- c(1,2,3,4,5)
> >> mean(c)
> >[1] 3
> >> c_mean <- mean(c)
> >> c
> >[1] 3
> >
> >having some experience in C, I thought the underscore is 
> "always" valid in
> >variable name. totally confuse me. Reread the R-FAQ a few 
> times, and found
> >on pg. 7 foot-note which states that;
> >
> >   the underscore character "_" is an alllowable synonym for the left
> >   pointing assignment operator "<-", ...........
> >   
> >it is appear that R parse  "c_mean <-  mean(c)" as "c <- 
> mean <- mean(c)",
> >which explain the result.
> >
> >suggestion:
> >
> >I believe it would be helpful if this point be make clear on 
> the FAQ, and
> >not mention as a footnote. What is a proper naming 
> convention and a few
> >example of valid/invalid name for variables.
> 
> Ah, but now that you have been bitten by it, I bet you don't 
> make the same
> mistake again!  :-)
> 
> There is a no-win situation here.  It is there (I presume) mainly for
> compatibility with S.  It is in S because some old keyboards 
> did not have
> an underscore but a left-pointing arrow at that same 
> position.  For better
> or worse we are stuck with it now.
> 
> If we follow your suggestion and give prominence to the fact 
> that "_" is a
> synonym for "<-" then as sure as eggs some people will 
> actually USE it!
> This is, in the opinion of many of us at least, a very BAD thing as it
> makes code just about unreadible.  On the other hand if we don't give
> prominence to the fact but just hide it in an obscure 
> footnote, then many
> people will get bitten first time (but only then) and come 
> complaining to
> R-help and I will write more tetchy little notes like this one...
> 
> :-)
> 
> Bill Venables.
> --
> Bill Venables, Statistician                         Tel. +61 
> 7 3826 7251 
> CSIRO Marine Laboratories,                          Fax. +61 
> 7 3826 7304
> Cleveland, Qld, 4163                  Email: 
> Bill.Venables at cmis.csiro.au
> AUSTRALIA                        
http://www.cmis.csiro.au/bill.venables/

Bill, 

This is actually beside the point.
The relevant thing to put on the FAQ that "_" is NOT
permitted as character in variable names...

No need to metion why...

Bendix

----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Centre
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 28 25 87 38
fax: +45 44 43 73 13
bxc at novo.dk
www.biostat.ku.dk/~bxc
----------------------



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list