Re: [R] Strange lazy evaluation of default arguments

2017-09-05 Thread Jeff Newmiller
William Dunlap >Gesendet: Samstag, 2. September 2017 19:41 >An: Rui Barradas >Cc: Matthias Gondan; r-help@r-project.org >Betreff: Re: [R] Strange lazy evaluation of default arguments > >Another way to avoid the problem is to not redefine variables that are >argume

Re: [R] Strange lazy evaluation of default arguments

2017-09-05 Thread Matthias Gondan
happen? [it’s documented behavior, but still…] So, I’ll stick with R. Still 25 years or so until retirement, but I’ll survive, even without crossreferenced default arguments. Best wishes, Matthias Von: S Ellison Gesendet: Dienstag, 5. September 2017 16:17 An: Matthias Gondan; r-help@r-project.

Re: [R] Strange lazy evaluation of default arguments

2017-09-05 Thread S Ellison
nt: 02 September 2017 18:22 > To: r-help@r-project.org > Subject: [R] Strange lazy evaluation of default arguments > > Dear R developers, > > sessionInfo() below > > Please have a look at the following two versions of the same function: > > 1. Intended behavior

Re: [R] Strange lazy evaluation of default arguments

2017-09-02 Thread Bert Gunter
This is exactly as expected. See section 4.3.3 of the R Language definition or google around on "R Lazy Evaluation" for details. You should not "expect" R's semantics to be the same as other languages with which you may be familiar. Spending time with a good tutorial or two should help you sort ou

Re: [R] Strange lazy evaluation of default arguments

2017-09-02 Thread Jeff Newmiller
Yes, this is intended behavior, and it has everything to do with where the parameters are first referenced and nothing to do with debugging. -- Sent from my phone. Please excuse my brevity. On September 2, 2017 10:22:22 AM PDT, Matthias Gondan wrote: >Dear R developers, > >sessionInfo() below

Re: [R] Strange lazy evaluation of default arguments

2017-09-02 Thread Matthias Gondan
mu=0.53, sigma2=4.3^2) # instead of l=u And maybe also „in-place“ changes of values… Best regards, Matthias Von: William Dunlap Gesendet: Samstag, 2. September 2017 19:41 An: Rui Barradas Cc: Matthias Gondan; r-help@r-project.org Betreff: Re: [R] Strange lazy evaluation of default argume

Re: [R] Strange lazy evaluation of default arguments

2017-09-02 Thread William Dunlap via R-help
Another way to avoid the problem is to not redefine variables that are arguments. E.g., > Su3 <- function(u=100, l=u, mu=0.53, sigma2=4.3^2, verbose) { if (verbose) { print(c(u, l, mu)) } uNormalized <- u/sqrt(sigma2) lNormalized <- l/sqrt(sigma2) muNormalized <- mu/sq

Re: [R] Strange lazy evaluation of default arguments

2017-09-02 Thread ruipbarradas
Hello, One way of preventing that is to use ?force. Just put force(l) right after the commented out print and before you change 'u'. Hope this helps, Rui Barradas Citando Matthias Gondan : Dear R developers, sessionInfo() below Please have a look at the following two versions of the

[R] Strange lazy evaluation of default arguments

2017-09-02 Thread Matthias Gondan
Dear R developers, sessionInfo() below Please have a look at the following two versions of the same function: 1. Intended behavior: > Su1 = function(u=100, l=u, mu=0.53, sigma2=4.3^2) + { + print(c(u, l, mu)) # here, l is set to u’s value + u = u/sqrt(sigma2) + l = l/sqrt(sigma2) + mu =