Re: [R] Evaluation of defaults in functions

From: Duncan Murdoch <>
Date: Fri 29 Sep 2006 - 11:07:28 GMT

On 9/28/2006 10:34 PM, hadley wickham wrote:

>> And, to answer the specific question: Yes, R has lazy evaluation,
>> everywhere. Arguments are always evaluated if and when they are
>> needed.

> But doesn't R has a rather limited force of lazy evaluation? - you
> have no control over it, apart from that arguments are evaluated
> lazily. This rather limited compared to other languages (no lazy
> lists etc)

You do have more control than that. You can't put a promise in a list, but you can put one in an environment, e.g.

 > x <- new.env()
 > y <- 1
 > delayedAssign("z", y, assign=x)
 > y <- 2
 > x$z

[1] 2

A few versions ago there was a delay() function that might have let you do this as

x$z <- delay(y)

but this doesn't really make sense: since assignment is a function call, why wouldn't it force the evaluation of the promise? The contortions necessary to work around this contradiction led to some strange errors, so delay was deprecated and is now defunct. (I don't really know what the result of the assignment above would have been.)

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri Sep 29 21:11:31 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 29 Sep 2006 - 14:30:07 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.