Sander
2010-Aug-04 09:38 UTC
[R] Question regarding S4 objects and reading in excel data with RODBC
L.S. I am trying to get data from an excel sheet using the RODBC library, quite like the example on page 34 of the 'Data manipulation with R' book written by Phil Spector. It seems very straightforward, yet I get the same error everytime I try it, with different excel sheets and trying to tweek the code a bit. This is what I do: library(RODBC) sheet='X:\\example.xls' con=odbcConnectExcel(sheet) tbls=sqlTables(con) tbls$TABLE_NAME qry=paste("SELECT * FROM '",tbls at TABLE_NAME[1],"'", sep=" ") The error I get is: Error in paste("SELECT * FROM '", tbls at TABLE_NAME[1], "'", sep = " ") : trying to get slot "TABLE_NAME" from an object (class "data.frame") that is not an S4 object Does anyone know what I'm doing wrong here? I have to admit that I don't know much about sql. Best regards, Sander van Kuijk -- View this message in context: http://r.789695.n4.nabble.com/Question-regarding-S4-objects-and-reading-in-excel-data-with-RODBC-tp2313170p2313170.html Sent from the R help mailing list archive at Nabble.com.
Duncan Murdoch
2010-Aug-04 11:09 UTC
[R] Question regarding S4 objects and reading in excel data with RODBC
On 04/08/2010 5:38 AM, Sander wrote:> L.S. > > I am trying to get data from an excel sheet using the RODBC library, quite > like the example on page 34 of the 'Data manipulation with R' book written > by Phil Spector. It seems very straightforward, yet I get the same error > everytime I try it, with different excel sheets and trying to tweek the code > a bit. This is what I do: > > library(RODBC) > > sheet='X:\\example.xls' > con=odbcConnectExcel(sheet) > > tbls=sqlTables(con) > tbls$TABLE_NAME > qry=paste("SELECT * FROM '",tbls at TABLE_NAME[1],"'", sep=" ") > > > The error I get is: > Error in paste("SELECT * FROM '", tbls at TABLE_NAME[1], "'", sep = " ") : > trying to get slot "TABLE_NAME" from an object (class "data.frame") that > is not an S4 objecttbls is not an S4 object, so you can't use the @ notation with it. In some older versions of R @ would extract an attribute (because that's where S4 slots were stored), but current versions don't allow this. Without testing, I would guess you can replace tbls at TABLE_NAME[1] with attr(tbls, "TABLE_NAME")[1] but it's possible the name is wrong. Duncan Murdoch> > Does anyone know what I'm doing wrong here? I have to admit that I don't > know much about sql. > > > Best regards, > > Sander van Kuijk