[R] using ``<-'' in function argument

Jinsong Zhao jszhao at yeah.net
Fri Dec 3 04:35:48 CET 2010


Hi there,

In function, it's usually using ``='' to assign default value for 
function argument. For newbie, it's possible to using ``<- '' to assign 
value for function argument. Although it's not a correct way, R don't 
give any warning message.

 > matrix(1:20, ncol <- 4)
      [,1] [,2] [,3] [,4] [,5]
[1,]    1    5    9   13   17
[2,]    2    6   10   14   18
[3,]    3    7   11   15   19
[4,]    4    8   12   16   20

It seems that R ignore the ``ncol <-'' and assign the value 4 to ``nrow''.

Would anyone here give a more detailed explanation about this? Thanks in 
advance!

Best regards,
Jinsong



More information about the R-help mailing list