My question is how do you extend rbind()
to work with a data.frame
subclass? I cannot seem to properly extend rbind()
to work with even a very simple subclass. The following example demonstrates the issue:
Subclass and method definition:
new_df2 <- function(x, ...)
{
stopifnot(is.data.frame(x))
structure(x, class = c("df2", "data.frame"), author = "some user")
}
rbind.df2 <- function(..., deparse.level = 1)
{
NextMethod()
}
I realize that extending rbind()
is not necessary in this case, but my grand plan is to use rbind.data.frame()
on a my subclass and then add a few additional checks/attributes to its result.
If you call the following, you get an error: Error in NextMethod() : generic function not specified
.
does not work:
t1 <- data.frame(a = 1:12, b = month.abb)
t2 <- new_df2(t1)
rbind(t2, t2)
I also tried using NextMethod(generic = "rbind")
, but in that case, you receive this error: Error in NextMethod(generic = "rbind") : wrong value for .Method
.
also does not work:
rbind.df2 <- function(..., deparse.level = 1)
{
NextMethod(generic = "rbind")
}
rbind(t2, t2)
I'm at wits end and guess at the limits of my understanding of subclasses/methods too. Thanks for any help.