This is historical and compatibility. The story as I heard it is that on the computer where the original S language was developed had a key that produced a left pointing arrow and that was used as the assignment operator (later <- was added as an alternative for other computer systems). When keyboards became more standardized, the equivalent key was '_' and so that became the assignment operator. When I first started learning S (before most of my current students were born) we did all the assignments using '_' like:
> x _ 3 Rather than the preferred > x <- 3 It did not take long for the aesthetics (and other reasons) to get me to start using the preferred '<-' method. About 10 years ago it was decided to allow '=' as an alternative where unambiguous (but us purists still like '<-' better) and '_' started to lose any need to be used anymore. Currently S+ still allows '_' for assignment, but gives a warning that it is deprecated (at least as of 8.1, which is the latest version that I have, I don't know if 8.2 is out yet) and R has stopped allowing '_' for assignment and allows it to be used in variable names. So, you can use names like some_variable in R, but if you try to port that code to S+ or older versions of R that will be parsed as assign the value of variable to some, not as a single variable name. And as far as conventions go, I expect that most (if not all) of R core are more like me in having developed their programming habits/conventions when '_' was an operator, not a valid part of a variable name. While it is probably possible to teach old dogs new tricks, I prefer being productive (and having R core produce the great code that they are) to spending that time changing to satisfy the whims of a new generation. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Peng Yu > Sent: Thursday, December 03, 2009 7:47 PM > To: r-h...@stat.math.ethz.ch > Subject: Re: [R] Naming conventions for R? > > On Thu, Dec 3, 2009 at 8:27 PM, Sharpie <ch...@sharpsteen.net> wrote: > > > > > > pengyu.ut wrote: > >> > >> There are documents for naming conventions for other languages. I'm > >> wondering if there is a document that clearly describes the > >> recommended naming convention for R. > >> > > > > > > You should browse this thread: > > > > http://n4.nabble.com/Google-s-R-Style-Guide-td901694.html#a901694 > > > > It was a pretty thorough discussion of style different guides for R. > > Why variables has to be of the form some.variable but not > some_variable? > > I have my local convention of having the file names and the variable > names following the same convention, for the reason that I may save a > variable in a file and it is easier to find the variable if the > variable and the file name follow the same convention. For example, > > save(list='x_x_x', file='x_x_x.RData') > > I other programming language like C++, there is no confusion > introduced by having the same convention on file names and variables. > I'm wondering why a different convention is chosen for R. > > ______________________________________________ > R-help@r-project.org 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. ______________________________________________ R-help@r-project.org 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.