======= 2005-12-06 22:16:17 伳侜佋佢伬伌佇伵佒佇佇伌伒伬仯伜======>Martin Maechler a 侀crit : > >> please, please, these trailing ";" are *so* ugly. >> This is GNU S, not C (or matlab) ! >> >> but I'll be happy already if you could >> drop these ugly empty statements at the end of your lines... > >May I disagree ? >I find missing ";" at end of lines *so* ugly. >Ugly/not ugly depends on our observer's eyes. > From my programmer point of view, I prefer to mark >clearly the end of the lines. >In many languages, it's safer to do it this way, >and I thank the R developers to permit it. >(in my opinion, it should even be mandatory). >(By the way, marking the end of lines with a unique symbol >makes also the job easier for the following treatment.) >And yes, I'm also a C programmer ;-) > > > {and I have another chain of argments why "<-" is so more > > expressive than "=" > >Why "<-" seems better than "=" is also quite mysterious for me. >There was a discussion about this point recently I think. >I believe in 99% of cases it's more for historical reason >(and perhaps also for some "snob" reasons). > >I am not at all a 20 years experienced R programmer, but I have >written several hundreds of R lines those 6 last months, >and until today didn't get any problem using "=" instead of "<-".I think it is NOT just for historical reason.see the following example:> rm(x) > mean(x=1:10)[1] 5.5> xError: object "x" not found> mean(x<-1:10)[1] 5.5> x[1] 1 2 3 4 5 6 7 8 9 10>But I'll read your chain of arguments with interest. > >______________________________________________ >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= = = = = = = = = = = = = = = = = = = 2005-12-06 ------ Deparment of Sociology Fudan University My new mail addres is ronggui.huang at gmail.com Blog:http://sociology.yculblog.com
McGehee, Robert
2005-Dec-06 16:31 UTC
[R] R is GNU S, not C.... [was "how to get or store ....."]
> Jan T. Kim wrote: > > There is a draft R Coding Convention available at > > http://www.maths.lth.se/help/R/RCC/ > > which may be useful for finding a style that is good because it is > widely used and therefore familiar to a large number of readers.--However, as the author Henrik Bengtsson points out "these guidelines are ours and not the R-developers." Perhaps a definitive style guide published by R core that ensured consistency among new base code would be a helpful addition. I personally find the above style guide extremely useful when multiple programmers work on the same project, and would welcome a formal endorsement or revision by the R developers. (And despite Henrik's elegant guide, I too leave off the semicolons at the end of the lines.) --Robert
Liaw, Andy
2005-Dec-06 18:04 UTC
[R] R is GNU S, not C.... [was "how to get or store ....."]
From: Martin Maechler> > >>>>> "P" == P Ehlers <ehlers at math.ucalgary.ca> > >>>>> on Tue, 06 Dec 2005 08:35:07 -0700 writes: > > P> vincent at 7d4.com wrote: > > >> Martin Maechler a ??crit : > >> > >> > >>> please, please, these trailing ";" are *so* ugly. > >>> This is GNU S, not C (or matlab) ! > >>> > >>> but I'll be happy already if you could > >>> drop these ugly empty statements at the end of your lines... > >> > >> > >> May I disagree ? > >> I find missing ";" at end of lines *so* ugly. > >> Ugly/not ugly depends on our observer's eyes. > >> From my programmer point of view, I prefer to mark > >> clearly the end of the lines. > >> In many languages, it's safer to do it this way, > >> and I thank the R developers to permit it. > >> (in my opinion, it should even be mandatory). > >> (By the way, marking the end of lines with a unique symbol > >> makes also the job easier for the following treatment.) > >> And yes, I'm also a C programmer ;-) > >> > >> > {and I have another chain of argments why "<-" is so more > >> > expressive than "=" > >> > >> Why "<-" seems better than "=" is also quite mysterious for me. > >> There was a discussion about this point recently I think. > >> I believe in 99% of cases it's more for historical reason > >> (and perhaps also for some "snob" reasons). > >> > >> I am not at all a 20 years experienced R programmer, but I have > >> written several hundreds of R lines those 6 last months, > >> and until today didn't get any problem using "=" > instead of "<-". > >> > >> But I'll read your chain of arguments with interest. > > > P> Well, I'll have to disagree a bit. While I don't care so much > P> about trailing ";" (as long as it does not become mandatory), > P> I don't like the use of "=" for assignment and that's > definitely > P> NOT for "snob" reasons, whatever those are. I just > think code is > P> *much* easier to read if assignment is distinguished from > P> argument settings. > > Thank you, Peter. Indeed, this is exactly the main of my arguments: > Since "=" is used quite often in S for argument setting in > function calls, *additionally* using "<-" for assignment is > more expressive. > Also, e.g., a2ps (a nice 'ASCII' to PostScript converter), comes > {at least on Debian Linux} preconfigured for R, and uses nice > typesetting for "<-"; similarly for ESS. > OTOH, it's pretty hard to correctly markup and differentiate > those "=" which are assignments from those which are function. > argument settings. > > P> Peter Ehlers > > [But really, I'm more concerned and quite bit disappointed by > the diehard ";" lovers] > > Martin MaechlerMatlab also allows both with and without ";", but I guess most people learn quickly what the preferred way is: Without ";", Matlab prints the output of commands, including assignments; e.g., if you assign a 1e5-row matrix to something, and didn't terminate the line with ";", Matlab will print that matrix to the console. Personally, having the extraneous ";" doesn't bother me nearly as much as not indenting the code properly or leave spaces around operators. I don't use them, because I seldom have difficulty knowing when a statement is suppose to end (given the code is properly indented). Those who use Python would know quite well, too, I guess. For those who insist on having ";", I guess they will never get the point of something like Python (or even Fortran...). Andy
vincent@7d4.com
2005-Dec-06 18:50 UTC
[R] R is GNU S, not C.... [was "how to get or store ....."]
ronggui a 仺仸crit :> I think it is NOT just for historical reason. > see the following example: > >>rm(x) >>mean(x=1:10) > [1] 5.5 >>x > Error: object "x" not foundx is an argument local to mean(), did you expect another answer ?>>mean(x<-1:10) > [1] 5.5 >>x > [1] 1 2 3 4 5 6 7 8 9 10What is the goal of this "example" ? Here with "<-", (voluntary, or not, side effect) the global variable x is, also, created. Did the writer really want that ??? I though there were other specific statements especially intended for global assignment, eg "<<-". If this example was intended to prove "<-" is better than "=" ... I'm not really convinced !
Liaw, Andy
2005-Dec-06 20:17 UTC
[R] R is GNU S, not C.... [was "how to get or store ....."]
From: vincent at 7d4.com> > ronggui a ??crit : > > > I think it is NOT just for historical reason. > > see the following example: > > > >>rm(x) > >>mean(x=1:10) > > [1] 5.5 > >>x > > Error: object "x" not found > > x is an argument local to mean(), > did you expect another answer ? > > >>mean(x<-1:10) > > [1] 5.5 > >>x > > [1] 1 2 3 4 5 6 7 8 9 10 > > What is the goal of this "example" ?I believe it's to show why "<-" is to be preferred over "=" for assignment...> Here with "<-", > (voluntary, or not, side effect) > the global variable x is, also, created. > Did the writer really want that ???Very much so, I believe.> I though there were other specific statements > especially intended for global assignment, eg "<<-".You need to distinguish assignment in function _call_ and assignment in function _definition_. They ain't the same.> If this example was intended to prove "<-" > is better than "=" > ... I'm not really convinced !In that case, let's try another one (which is one big reason I stopped using "=" for assignment):> long.comp <- function(n) {+ Sys.sleep(n) + n + }> result = long.comp(30) > system.time(result = long.comp(30))Error in system.time(result = long.comp(30)) : unused argument(s) (result ...)> system.time(result <- long.comp(30))[1] 0.00 0.00 30.05 NA NA> str(result)num 30 Cheers, Andy>
Hong Ooi
2005-Dec-06 23:57 UTC
[R] R is GNU S, not C.... [was "how to get or store ....."]
_______________________________________________________________________________________ Hm, a style war on R-Help. I wonder if this goes for long enough, we'll come to the question of where to put the braces. ;) Personally, I always use <- instead of = where applicable. In addition to the distinction between assignment and naming arguments in function calls, it helps avoid the notorious =/== bug from C programming. Compare "if(x == 1) {..." /* comparison -- probably what was wanted */ with "if(x = 1) {..." /* oops */ This has bitten me a number of times in C, so I'd like to avoid it in R/S. Using "if(identical(x, 1)) {..." also addresses this problem, but that just looks awkward to me. -- Hong Ooi Senior Research Analyst, IAG Limited 388 George St, Sydney NSW 2000 +61 (2) 9292 1566 -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Liaw, Andy Sent: Wednesday, 7 December 2005 7:17 AM To: 'vincent at 7d4.com'; r-help at stat.math.ethz.ch Subject: Re: [R] R is GNU S, not C.... [was "how to get or store ....."] From: vincent at 7d4.com> > ronggui a ??crit : > > > I think it is NOT just for historical reason. > > see the following example: > > > >>rm(x) > >>mean(x=1:10) > > [1] 5.5 > >>x > > Error: object "x" not found > > x is an argument local to mean(), > did you expect another answer ? > > >>mean(x<-1:10) > > [1] 5.5 > >>x > > [1] 1 2 3 4 5 6 7 8 9 10 > > What is the goal of this "example" ?I believe it's to show why "<-" is to be preferred over "=" for assignment...> Here with "<-", > (voluntary, or not, side effect) > the global variable x is, also, created. > Did the writer really want that ???Very much so, I believe.> I though there were other specific statements > especially intended for global assignment, eg "<<-".You need to distinguish assignment in function _call_ and assignment in function _definition_. They ain't the same.> If this example was intended to prove "<-" > is better than "=" > ... I'm not really convinced !In that case, let's try another one (which is one big reason I stopped using "=" for assignment):> long.comp <- function(n) {+ Sys.sleep(n) + n + }> result = long.comp(30) > system.time(result = long.comp(30))Error in system.time(result = long.comp(30)) : unused argument(s) (result ...)> system.time(result <- long.comp(30))[1] 0.00 0.00 30.05 NA NA> str(result)num 30 Cheers, Andy>______________________________________________ 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 _______________________________________________________________________________________ The information transmitted in this message and its attachme...{{dropped}}
======= 2005-12-07 04:17:03 伳侜佋佢伬伌佇伵佒佇佇伌伒伬仯伜======>From: vincent at 7d4.com >> >> ronggui a 侀crit : >> >> > I think it is NOT just for historical reason. >> > see the following example: >> > >> >>rm(x) >> >>mean(x=1:10) >> > [1] 5.5 >> >>x >> > Error: object "x" not found >> >> x is an argument local to mean(), >> did you expect another answer ? >> >> >>mean(x<-1:10) >> > [1] 5.5 >> >>x >> > [1] 1 2 3 4 5 6 7 8 9 10 >> >> What is the goal of this "example" ? > >I believe it's to show why "<-" is to be preferred over "=" for >assignment...Yeah,I want to show "<-" is to be preferred. Sorry for not making it clearly.>> Here with "<-", >> (voluntary, or not, side effect) >> the global variable x is, also, created. >> Did the writer really want that ??? > >Very much so, I believe. > >> I though there were other specific statements >> especially intended for global assignment, eg "<<-". > >You need to distinguish assignment in function _call_ and assignment in >function _definition_. They ain't the same. > >> If this example was intended to prove "<-" >> is better than "=" >> ... I'm not really convinced ! > >In that case, let's try another one (which is one big reason I stopped using >"=" for assignment): > > >> long.comp <- function(n) { >+ Sys.sleep(n) >+ n >+ } >> result = long.comp(30) >> system.time(result = long.comp(30)) >Error in system.time(result = long.comp(30)) : > unused argument(s) (result ...) >> system.time(result <- long.comp(30)) >[1] 0.00 0.00 30.05 NA NA >> str(result) > num 30 > >Cheers, >Andy > >> > >______________________________________________ >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= = = = = = = = = = = = = = = = = = = 2005-12-07 ------ Deparment of Sociology Fudan University My new mail addres is ronggui.huang at gmail.com Blog:http://sociology.yculblog.com
GuangXing
2005-Dec-07 01:03 UTC
[R] R is GNU S, not C.... [was "how to get or store ....."]
I think "<-" is better than "=" in some cases. ======= 2005-12-07 08:51:30 Write仯伜======> > >======= 2005-12-07 04:17:03 伳侜佋佢伬伌佇伵佒佇佇伌伒伬仯伜======> >>From: vincent at 7d4.com >>> >>> ronggui a 侀crit : >>> >>> > I think it is NOT just for historical reason. >>> > see the following example: >>> > >>> >>rm(x) >>> >>mean(x=1:10) >>> > [1] 5.5 >>> >>x >>> > Error: object "x" not found >>> >>> x is an argument local to mean(), >>> did you expect another answer ? >>> >>> >>mean(x<-1:10) >>> > [1] 5.5 >>> >>x >>> > [1] 1 2 3 4 5 6 7 8 9 10 >>> >>> What is the goal of this "example" ? >> >>I believe it's to show why "<-" is to be preferred over "=" for >>assignment... > >Yeah,I want to show "<-" is to be preferred. >Sorry for not making it clearly. > >>> Here with "<-", >>> (voluntary, or not, side effect) >>> the global variable x is, also, created. >>> Did the writer really want that ??? >> >>Very much so, I believe. >> >>> I though there were other specific statements >>> especially intended for global assignment, eg "<<-". >> >>You need to distinguish assignment in function _call_ and assignment in >>function _definition_. They ain't the same. >> >>> If this example was intended to prove "<-" >>> is better than "=" >>> ... I'm not really convinced ! >> >>In that case, let's try another one (which is one big reason I stopped using >>"=" for assignment): >> >> >>> long.comp <- function(n) { >>+ Sys.sleep(n) >>+ n >>+ } >>> result = long.comp(30) >>> system.time(result = long.comp(30)) >>Error in system.time(result = long.comp(30)) : >> unused argument(s) (result ...) >>> system.time(result <- long.comp(30)) >>[1] 0.00 0.00 30.05 NA NA >>> str(result) >> num 30 >> >>Cheers, >>Andy >> >>> >> >>______________________________________________ >>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 > >= = = = = = = = = = = = = = = = = = = > > > > > >2005-12-07 > >------ >Deparment of Sociology >Fudan University > >My new mail addres is ronggui.huang at gmail.com >Blog:http://sociology.yculblog.com > > >______________________________________________ >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= = = = = = = = = = = = = = = = = = = 仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭GuangXing 仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭guangxing at ict.ac.cn 仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭仭2005-12-07