From: GuangXing <guangxing_at_ict.ac.cn>

Date: Wed 07 Dec 2005 - 12:03:41 EST

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Dec 07 12:10:43 2005

Date: Wed 07 Dec 2005 - 12:03:41 EST

I think "<-" is better than "=" in some cases.

- 2005-12-07 08:51:30 Write：=======

*>
**>
*

>======= 2005-12-07 04:17:03 您在来信中写道：=======

*>
**>>From: vincent@7d4.com
**>>>
**>>> ronggui a 閏rit :
**>>>
**>>> > 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@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@gmail.com
**>Blog:http://sociology.yculblog.com
**>
**>
**>______________________________________________
**>R-help@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@ict.ac.cn 2005-12-07R-help@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 Received on Wed Dec 07 12:10:43 2005

*
This archive was generated by hypermail 2.1.8
: Wed 07 Dec 2005 - 14:29:09 EST
*