From hamstersquats at web.de  Thu Mar 12 11:15:40 2009
From: hamstersquats at web.de (Thomas Roth (geb. Kaliwe))
Date: Thu, 12 Mar 2009 11:15:40 +0100
Subject: [Rd] S4 coerce as.data.frame for lm
Message-ID: <49B8E0CC.3040905@web.de>

#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

temp at 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 at 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.



[Rd] S4 coerce as.data.frame for lm
Thomas Roth (geb. Kaliwe