[R] problem with sqlSave()

Ivan Calandra ivan.calandra at uni-hamburg.de
Wed Feb 24 09:55:57 CET 2010


Dear R users,

I've already asked this question yesterday, but, though I had answer for 
the other ones (and they helped a lot, thanks), for some reason didn't 
get an answer for this one (I would also appreciate to know why, so that 
I can improve the quality and clarity of my future questions).

Here it is again:

I'm trying to use RODBC to export dataframes to xls files.
When I run this code I get an error:
 > test <- structure(list(Group = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 
4, 4, 5), Group = c(2, 3, 4, 5, 6, 3, 4, 5, 6, 4, 5, 6, 5, 6, 6), test = 
c(0.907901716802262, 0.344080298502179, 0.780331168285069, 
2.15033450900747, 0.194069709110157, 0.406313481811673, 
0.116434832984871, 1.52727249397868, 0.579195268552845, 
0.420998518182892, 1.62939679051865, 0.138892090710994, 
1.11253003450962, 0.555496810201502, 1.78610263147685), crit = 
c(2.97744276941854, 2.98843563665370, 3.05786246930315, 
3.00681172135752, 2.99644239171413, 3.00036808377006, 3.07797861408659, 
3.02408697737205, 3.01060847439059, 3.03639474502811, 2.99664917266571, 
2.99135011459308, 3.04177033698215, 3.04239401519992, 3.00305006434149), 
se = c(12.1028423223510, 15.1532795810610, 16.3991441261986, 
15.3598663144688, 14.9271014453042, 14.2113088036481, 15.5329116369945, 
14.4313862483545, 13.9698880958026, 18.0115083683957, 17.0706765780184, 
16.6823518483263, 18.1856549192307, 17.8216415967046, 16.8702244895529), 
df = c(99.682919819226, 89.3039016709219, 50.9067902231679, 
76.0647290534967, 83.0087667496558, 80.2356900159524, 43.4849997568059, 
66.760479193059, 73.8040951542063, 61.4088750589742, 82.8579246229594, 
86.904905246028, 58.9562752558462, 58.5971747302359, 78.4453136851244)), 
.Names = c("Group", "Group", "test", "crit", "se", "df"), row.names = 
c(NA, -15L), class = "data.frame")
 > xlsFile <- odbcConnectExcel("output.xls", readOnly=F)    ##the file 
is created here, it didn't exist before here
 > sqlSave(xlsFile, test, tablename="test1", rownames=F, addPK=T, append=T)
Error in sqlSave(xlsFile, test, tablename = "test1", rownames = F, addPK 
= T,  :
   HYS21 -1508 [Microsoft][Pilote ODBC Excel] Le champ 'Group' existe 
déjà dans la table 'test1'.
[RODBC] ERROR: Could not SQLExecDirect 'CREATE TABLE [test1]  ("Group" 
NUMBER, "Group" NUMBER, "test" NUMBER, "crit" NUMBER, "se" NUMBER, "df" 
NUMBER)'

The translation would be "the field 'Group' already exists in the sheet 
'test1'".

It does create the sheet "test1" but does not copy the data.
It is obviously a problem with this dataset because it works with this 
for example:
temp.df <- data.frame(a = rnorm(10), b = runif(10))
But I have no idea what could be wrong.

Could you please help me with this?
Thanks in advance
Regards,
Ivan



More information about the R-help mailing list