Skip to content
Prev 357862 / 398500 Next

Strange behavior with S3 class

You are absolutely right I made a mistake describing the problem.

So my question is how I can implement the "names" method for my class 
without having this problem. The following piece of code reproduce the 
problem I am facing.

names.eem <- function(x, ...){
   x$sample
}

# First constructor
eem1 <- function(sample){
   eem <- list(sample = sample)
   class(eem) <- "eem"
   return(eem)
}

# Second constructor
eem2 <- function(sample){
   eem <- list(sample = sample)
   class(eem) <- "eem2"
   return(eem)
}

test1 <- eem1("justaname")
test2 <- eem2("justaname")

str(test1)
str(test2)

Thank you for your help,
Philippe