[R] variable names when using S3 methods
Aaron Rendahl
arendahl at stat.umn.edu
Mon Apr 28 13:49:31 CEST 2008
I'm seeing some funny behavior when using methods (the older S3 type)
and having variables that start with the same letter. I have a vague
recollection of reading something about this once but now can't seem
to find anything in the documentation. Any explanation, or a link to
the proper documentation, if it does exist, would be appreciated.
Thanks, Aaron Rendahl
University of Minnesota School of Statistics
# set up two function that both use method "foo" but with different
variable names
fooA<-function(model,...)
UseMethod("foo")
fooB<-function(Bmodel,...)
UseMethod("foo")
# now set up two methods (default and character) that have an
additional variable
foo.character <- function(model, m=5,...)
cat("foo.character: m is", m, "\n")
foo.default <- function(model, m=5,...)
cat("foo.default: m is", m, "\n")
# both of these use foo.character, as expected
fooA("hi")
fooB("hi")
# but here, fooA uses foo.default instead
fooA("hi",m=1)
fooB("hi",m=1)
# additionally, these use foo.character, as expected
fooA("hi",1)
fooA(model="hi",m=1)
More information about the R-help
mailing list