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 cmis.csiro.au/bill.venables -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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. zamri -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 2 Oct 2000, 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 foundR is not C, and the set of allowed names is not at all the same.> 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.It would be helpful to give a naming convention, but this is obscured by the fact that names can often be quoted. So "c_mean" *is* a valid name.> "c_mean" <- mean(1:5) > get("c_mean")[1] 3 Names which can be used without quoting them contain A-Z, a-z, 0-9 and ., but may not start with 0-9 and . The definition of A-Z, a-z is locale-dependent, that is, it is all chars that are considered to be alphabetic in the locale. That may not be what you expect, especially on Windows (1.2.0 will be better). Unfortunately, the only place this seems to be written down is in the unfinished (and unreleased) R Language Manual and in various places in the Venables & Ripley books. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, stats.ox.ac.uk/~ripley University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Bill Venables <Bill.Venables at cmis.csiro.au> writes:> 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...Of course, there's also the option of letting the parser say "obsolete use of underscore as assignment operator" every time it is used. This just might annoy people enough to persuade them to stop using it... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> -----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 > AUSTRALIAcmis.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 biostat.ku.dk/~bxc ---------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help mailing list -- Read 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 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This seems as good a place as any to gripe about the R/S assignment symbol "<-" ! What absolute fiend said: "now let's see, this is the symbol that will be most used in this language, so let's represent it by a two-character string, and further, let's have the two characters in different cases so that it will require a change of case mid-stream!". Murray Jorgensen At 04:08 PM 2-10-00 +1000, Bill Venables wrote:>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 cmis.csiro.au/bill.venables > > >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.->r-help mailing list -- Read 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 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Patrick Connolly
2000-Oct-02 23:09 UTC
[R] Unreadable code: was the underscore ("_") in variables
According to Bill Venables: |> 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. It appears somewhat different from my perspective. I got into the habit of using emacs S-mode early in my time with the S language. Being a lazy typist, I found it convenient to use the parser to expand the assignments, add spaces and generally make readable any code I wished to use again (such as in functions). To anyone looking over my shoulder it might look crude, but it works quickly and safely as I am concerned. BTW: this no longer works using ESS as far as I can tell. To a lazy typist this is a sad loss. Has anyone found a way to return this functionality? -- Patrick Connolly HortResearch Mt Albert Auckland New Zealand Ph: +64-9 815 4200 x 7188 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ I have the world's largest collection of seashells. I keep it on all the beaches of the world ... Perhaps you've seen it. ---Steven Wright ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Just a vote for "<-". Once I became familiar with the convention using APL, I really began to appreciate the value of distinguishing assignment from equality. Also, the "<-" is clear and fairly unambiguous. Using NEdit, it is trivial to create a macro (Alt= for example) that will type the assignment symbol for you. If you use the left and right assignment operators often, perhaps Ctrl= and Alt= would be a simple way to get these combinations. Jim -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ben at zoo.ufl.edu writes:> Could ESS indeed be programmed to insert "<-" when one typed "_" ?I have something like the following in my .emacs file to do that: (add-hook 'inferior-ess-mode-hook '(lambda () (define-key inferior-ess-mode-map "_" "<-"))) -- Ed Kademan 508.651.3700 PHZ Capital Partners 508.653.1745 (fax) 321 Commonwealth Road <kademan at phz.com> Wayland, MA 01778 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jim Lemon <bitwrit at ozemail.com.au> writes:>Just a vote for "<-". Once I became familiar with the convention using >APL, I really began to appreciate the value of distinguishing assignment >from equality. Also, the "<-" is clear and fairly unambiguous. Using >NEdit, it is trivial to create a macro (Alt= for example) that will type >the assignment symbol for you. If you use the left and right assignment >operators often, perhaps Ctrl= and Alt= would be a simple way to get >these combinations.Just to add my tuppence ... when I first started using R I though it was a bit silly to have a two character assignment operator but later I saw the utility of having separate assignment (<-), equality (==), and parameter passing (=) symbols. I also find -> useful during function development. Also, PASCAL and MODULA use := for assignment. You get used to it. IMO, better the <- than the _ operator. As I say, just my tuppence. Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._