Hi, all,
Last week I described a possible bug with "...":
R> myfun <- function(x, ...) {x[...] <- 0;  x}
R> x <- matrix(1:12, 3,4)
R> myfun(x)
   Error in myfun(x) : SubAssignArgs: invalid number of arguments
I had a solution:
R> myfun <- function(x, ...) {if (missing(...)) x[]<-0 else
x[...]<-0; x}
Here is another, probably related, problem:
R> myfun2 <- function(x, ...) myfun(x, ...)
R> myfun2(x, ,1:2)
   Error in myfun(x, ...) : Argument is missing, with no default
Any ideas how to fix this up?  I could, of course, explicitly pass all args:
R> myfun2(x, 1:dim(x)[1], 1:2)
        [,1] [,2] [,3] [,4]
   [1,]    0    0    7   10
   [2,]    0    0    8   11
   [3,]    0    0    9   12
Thanks!
					-- David Brahm (brahm at alum.mit.edu)
"I write this letter not to nag nor to whine, but to prod." - Lisa
Simpson
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I wrote on 10/8/01 that I could not pass missing arguments from one function
to another through "...":
R> x <- matrix(1:12, 3,4)
R> myfun <- function(x, ...) {if (missing(...)) x[]<-0 else
x[...]<-0; x}
R> myfun2 <- function(x, ...) myfun(x, ...)
R> myfun2(x, ,1:2)
   Error in myfun(x, ...) : Argument is missing, with no default
Here is one solution:
R> myfun2 <- function(x, ...) {
R>   sc <- sys.call()
R>   sc[[1]] <- as.name("myfun")
R>   eval.parent(sc)
R> }
R> myfun2(x, ,1:2)
       [,1] [,2] [,3] [,4]
  [1,]    0    0    7   10
  [2,]    0    0    8   11
  [3,]    0    0    9   12
Comments?  Is this in any way inefficient or dangerous?  Thanks.
		-- David Brahm (brahm at alum.mit.edu)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._