R-alpha: lazy evaluation and plot.step()

Kurt Hornik Kurt.Hornik@ci.tuwien.ac.at
Tue, 22 Apr 1997 18:33:36 +0200


>>>>> Peter Dalgaard BSA writes:

> The explanation seems to be in different behaviour of the
> substitute(...) construction:

> R:
>> f<-function(a,b){a<-1; print(deparse(substitute(c(a,b))))}
>> f(a,b)
> [1] "c(1, b)"

> Splus:
>> f<-function(a,b){a<-1; print(deparse(substitute(c(a,b))))}
>> f(a,b)
> [1] "c(a, b)"
> [1] "c(a, b)"

> So in R, assignment to a formal parameter causes the changed value to
> be used for substitution purposes.

> In S, this does not happen *unless the formal parameter is a
> constant.*!

>> f(2,b)
> [1] "c(1, b)"
> [1] "c(1, b)"
>> f(2:2,b)
> [1] "c(2:2, b)"
> [1] "c(2:2, b)"
>> f("a",b)    
> [1] "c(1, b)"
> [1] "c(1, b)"

> This is confusing in both languages, but I'd say that S has the bigger
> problem...

Not a surprise ...

Thanks, Peter, for the explanation.  Does this also explain the
different results for x <- sort(x)?

> In Kurts example, inserting 

> xlab 
> ylab

> as the first two lines of the function defeats lazy evaluation and
> provides the desired behaviour (I suppose) in both R and S.

Yes.  This is also what I suggested to Martin in order to have a version
of plot.step() which does the same under R and S.

-k
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-