[R] using ``<-'' in function argument
Claudia Beleites
cbeleites at units.it
Fri Dec 3 12:10:12 CET 2010
On 12/03/2010 06:54 AM, Berwin A Turlach wrote:
> On Thu, 2 Dec 2010 23:34:02 -0500
> David Winsemius<dwinsemius at comcast.net> wrote:
>
>> [...] Erik is telling you that your use of ncol<-4 got evaluated to
>> 4 and that the name of the resulting object was ignored, howevert the
>> value of the operation was passed on to matrix which used positional
>> matching since "=" was not used.
>
> Sounds like a fair summary of what Erik said, but it is subtly wrong.
> R has lazy evaluation of its arguments. There is nothing that forces
> the assignment to be evaluated and to pass the result into the
> function. On the contrary, the assignment takes place when the
> function evaluates the argument.
Let's say: as no argument name was given, the positional matching applied. And
evaluation took place when argument no. 2 was required.
Of course, you could give an argument name:
> matrix(ncol <- 4)
[,1]
[1,] 4
> matrix(nrow = ncol <- 4)
[,1]
[1,] NA
[2,] NA
[3,] NA
[4,] NA
Claudia
--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste
phone: +39 0 40 5 58-37 68
email: cbeleites at units.it
More information about the R-help
mailing list