From hb@maths.lth.se  Fri Nov 16 16:00:02 2001
From: hb@maths.lth.se (hb@maths.lth.se)
Date: Fri, 16 Nov 2001 17:00:02 +0100 (MET)
Subject: [Rd] UseMethod() fails to (PR#1176)
Message-ID: <200111161600.RAA02600@pubhealth.ku.dk>

match the argument 'x' if there is another argument with prefix 'x'

Full_Name: Henrik Bengtsson
Version: 1.3.1
OS: Sun Solaris 8
Submission from: (NULL) (130.235.3.49)


I ran into a strange problem with UseMethod(). Run the following code:

foo.Bar <- function(this, x=0, xidx=0) {
  cat("In foo.Bar(): ", this, ", x=", x, ", xidx=", xidx, ".\n", sep="");
}

foo.default <- function(x, ...) {
  str("Error: No default function found!");
}

foo <- function(x, ...) UseMethod("foo");


obj <- "Hello world!";
class(obj) <- "Bar";

foo(obj);
foo(obj, xidx=1);
foo(obj, x=1);             # <- PROBLEM HERE!
foo(obj, x=1, xidx=1);     # <- PROBLEM HERE!
foo(obj, xidx=1, x=1);     # <- PROBLEM HERE!
foo.Bar(obj, x=1);
foo.Bar(obj, x=1, xidx=1);

and you will get

  In foo.Bar(): Hello world!, x=0, xidx=0.
  In foo.Bar(): Hello world!, x=0, xidx=1.
   chr "Error: No default function found!"
   chr "Error: No default function found!"
   chr "Error: No default function found!"
  In foo.Bar(): Hello world!, x=1, xidx=0.
  In foo.Bar(): Hello world!, x=1, xidx=1.

There is something going on with matching of arguments; UseMethod() fails to
match the argument 'x' if there is another argument with prefix 'x'.

I believe this is an unwanted feature of UseMethod.

Thanks

Henrik Bengtsson
Lund University
Sweden


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] UseMethod() fails to (PR#1176)
hb@maths.lth.se