[R] why-s of method dispatching

Vadim Ogranovich vograno at evafunds.com
Wed Mar 17 23:48:51 CET 2004


Hi,

I am having a problem to understand why as.data.frame method doesn't
dispatch properly on my class:

> setClass("Foo", "character")
[1] "Foo"
> as.data.frame(list(foo=new("Foo", .Data="a")))
Error in as.data.frame.default(x[[i]], optional = TRUE) : 
 can't coerce Foo into a data.frame

I was expecting that this would call as.data.frame.character.


Another puzzle. If I explicitly call as.data.frame.character() it would
fail but for a different reason:

> as.data.frame.character(list(foo=new("Foo", .Data="a")))
Error in unique.default(x) : unique() applies only to vectors


I was under an impression that an instance of "Foo" would be welcome
anywhere a "character" was, but it seems to be more subtle. What am I
missing?


Thanks,
Vadim




More information about the R-help mailing list