#Hi,
#
#I posted this already on r-help... with no success :-(
#
#For a given class test, an object of class test cannot be used as data in the lm method although as.data.frame was implemented... where's my mistake?
#
#Suppose i have defined a S4 class test

#S4 Class test containting a slot data
#which is of type data.frame

setClass(Class = "test", representation = representation(name = "character", data = "data.frame") temp = new("test") #temp is of class test

t...@data = faithful   #assign some data to it

#now define as.data.frame for class test
setMethod("as.data.frame", "test", function(x, row.names = NULL, optional = FALSE)
{

return(x...@data)

}
)

as.data.frame(temp)   #works

lm(eruptions ~ waiting, data = temp)   #doesn't work


#Thank you for any hints
#Thomas Roth



#from the lm help page
|#data| - an optional data frame, list or environment (or object coercible by |as.data.frame| to a data frame) containing the variables in the model. If not found in |data|, the variables are taken from |environment(formula)|, typically the #environment from which |lm| is called.

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to