Martin Maechler
1997-May-09 13:38 UTC
R-alpha: R-0.49 / S-plus: "default argument evaluation" bugs and woes
There is a problem with 'default argument evaluation' when I use an existing function name as argument name : sintest <- function(x, y = 2, sin= sin(pi/4)) { ## Purpose: Test of "default argument evaluation" ## -------- Fails for R-0.49. Martin Maechler, Date: 9 May 97. c(x=x, y=y, sin=sin) } ## R-0.49: R> sintest(1) ##> Error in sintest(1) : recursive default argument reference ## S-plus 3.4 (being 100% ok): S> sintest(1) x y sin 1 2 0.7071068 Warning messages: looking for function "sin", ignored local non-function in: sintest(1) ------------------------------------------------------- The following shows bugs, both in R and S: sintest2 <- function(x ,y = 2) { ## Purpose: Test of "default argument evaluation" ## -------- Fails for S-plus 3.4. Martin Maechler, Date: 9 May 97. c(x=x, y=y, sin=sin) } R> sintest2(1) [[1]] [1] 1 [[2]] [1] 2 [[3]] <primitive: sin> --------------- is almost okay, the buglet being that the names have been dropped from the list. But watch this: S> sintest2(1) function(x = 1, y = 2, sin.x) sin2 = .Internal(sin(x), "do_math", T, 109) --- returning a function ((now we see, why S's way of treating functions as lists sometimes badly sucks)). =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Luke Tierney
1997-May-09 14:52 UTC
R-alpha: R-0.49 / S-plus: "default argument evaluation" bugs and woes
Martin Maechler wrote:> > > There is a problem with 'default argument evaluation' > when I use an existing function name as argument name : > > sintest <- function(x, y = 2, sin= sin(pi/4)) > { > ## Purpose: Test of "default argument evaluation" > ## -------- Fails for R-0.49. Martin Maechler, Date: 9 May 97. > c(x=x, y=y, sin=sin) > } > > ## R-0.49: > R> sintest(1) > ##> Error in sintest(1) : recursive default argument reference > > ## S-plus 3.4 (being 100% ok): > S> sintest(1) > x y sin > 1 2 0.7071068 > Warning messages: > looking for function "sin", ignored local non-function in: sintest(1) > > ------------------------------------------------------- > The following shows bugs, both in R and S: > > sintest2 <- function(x ,y = 2) > { > ## Purpose: Test of "default argument evaluation" > ## -------- Fails for S-plus 3.4. Martin Maechler, Date: 9 May 97. > c(x=x, y=y, sin=sin) > } > > R> sintest2(1) > [[1]] > [1] 1 > > [[2]] > [1] 2 > > [[3]] > <primitive: sin> >For better or worse, S and R allow default expressions to contain references variables that are (or rather may be) created in the function body, so (in R and Splus)> x<-1 > f<-function(a,b=x) { if (a) x<-2; b} > f()Error: Argument "a" is missing, with no default> f(T)[1] 2> f(F)[1] 1 More traditional lexical scoping would make the reference to x in the default always be global, but lots of code would break. I think we're stuck with this behavior as a corollary to the way S wants default arguments to work. Actually S is a bit inconsistent in its error message -- if you have a non-function argument it gives the same message as R,> g<-function(x=x) x >g()Error in g(): Recursive occurrence of default argument "x" Dumped Also in R's lexical scoping you probably do want the argument name to shadow any outer definitions if you want to be able to define default arguments that are recursive functions, e.g.> g<-function(n, nfac=function(x) { if (x <= 1) 1 else nfac(x-1)*x }) nfac(n); > g(6)[1] 720 -- Luke Tierney University of Minnesota Phone: 612-625-7843 School of Statistics Fax: 612-624-8868 206 Church Street email: luke@stat.umn.edu Minneapolis, MN 55455 USA WWW: http://www.stat.umn.edu =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
lm.influence() doesn't work correctly on weighted models (and thus on glm objects). Thomas Lumley ------------------------------------------------------+------ Biostatistics : "Never attribute to malice what : Uni of Washington : can be adequately explained by : Box 357232 : incompetence" - Hanlon's Razor : Seattle WA 98195-7232 : : ------------------------------------------------------------ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-