[R] Evaluation of defaults in functions

2006-09-28 Thread Ulrich Keller
Hello, and sorry if this is already explained somewhere. I couldn't find anything. R (2.3.1, Windows) seems to perform some kind of lazy evaluation when evaluating defaults in function calls that, at least for me, leads to unexpected results. Consider the following, seemingly equivalent functio

Re: [R] Evaluation of defaults in functions

2006-09-28 Thread Deepayan Sarkar
On 9/28/06, Ulrich Keller <[EMAIL PROTECTED]> wrote: > Hello, > > and sorry if this is already explained somewhere. I couldn't find anything. > > R (2.3.1, Windows) seems to perform some kind of lazy evaluation when > evaluating defaults in function calls that, at least for me, leads to > unexpecte

Re: [R] Evaluation of defaults in functions

2006-09-28 Thread Marc Schwartz (via MN)
On Thu, 2006-09-28 at 21:49 +0200, Ulrich Keller wrote: > Hello, > > and sorry if this is already explained somewhere. I couldn't find anything. > > R (2.3.1, Windows) seems to perform some kind of lazy evaluation when > evaluating defaults in function calls that, at least for me, leads to > un

Re: [R] Evaluation of defaults in functions

2006-09-28 Thread Gabor Grothendieck
foo2 could be written: foo3 <- function(x, y = x) { force(y); x <- 0; y } to make it clear that evaluation of y is being forced. See ?force On 9/28/06, Ulrich Keller <[EMAIL PROTECTED]> wrote: > Hello, > > and sorry if this is already explained somewhere. I couldn't find anything. > > R (2.3

Re: [R] Evaluation of defaults in functions

2006-09-28 Thread Peter Dalgaard
"Gabor Grothendieck" <[EMAIL PROTECTED]> writes: > foo2 could be written: > >foo3 <- function(x, y = x) { force(y); x <- 0; y } > > to make it clear that evaluation of y is being forced. See ?force And, to answer the specific question: Yes, R has lazy evaluation, everywhere. Arguments are

Re: [R] Evaluation of defaults in functions

2006-09-28 Thread hadley wickham
> > 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 rath

Re: [R] Evaluation of defaults in functions

2006-09-28 Thread Prof Brian Ripley
On Thu, 28 Sep 2006, 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, apar

Re: [R] Evaluation of defaults in functions

2006-09-29 Thread Duncan Murdoch
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

Re: [R] Evaluation of defaults in functions

2006-09-29 Thread hadley wickham
> > 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

Re: [R] Evaluation of defaults in functions

2006-09-29 Thread Gabor Grothendieck
On 9/29/06, hadley wickham <[EMAIL PROTECTED]> wrote: > > > 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

Re: [R] Evaluation of defaults in functions

2006-09-29 Thread Duncan Murdoch
On 9/29/2006 10:12 AM, hadley wickham wrote: >> > 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 co

Re: [R] Evaluation of defaults in functions

2006-09-29 Thread Luke Tierney
On Fri, 29 Sep 2006, Prof Brian Ripley wrote: > On Thu, 28 Sep 2006, 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

Re: [R] Evaluation of defaults in functions

2006-09-29 Thread hadley wickham
> There are not all that many other languages that use lazy evaluation. > Those that do are for the most part pure or nearly pure functional > languages--Haskell is probably the main example. These go much > further in their use of lazy evaluation than R. For analogs of the R > expressions > >

Re: [R] Evaluation of defaults in functions

2006-09-29 Thread Luke Tierney
On Fri, 29 Sep 2006, hadley wickham wrote: >> There are not all that many other languages that use lazy evaluation. >> Those that do are for the most part pure or nearly pure functional >> languages--Haskell is probably the main example. These go much >> further in their use of lazy evaluation th