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 '",t...@table_name[1],"'", sep=" ")
The error I get is:
Error in paste("SELECT * FROM '", t...@table_name[1], "'", sep = " ") :
trying to get slot "TABLE_NAME" from an object (class "data.frame") that
is not an S4 object
tbls 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
t...@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
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.