Dear R users,
I have a follow-up question on sqlSave().
Since most of the output from the tests I use are lists, I would like to
loop to export each element of the list and append it to the sheet.
Here is what I do:
> library(RODBC)
> test <- structure(list(m = structure(c(0.090909090909091,
0.181818181818182,
0.272727272727273, 0.363636363636364, 0.454545454545455, 0.545454545454545,
0.636363636363636, 0.727272727272727, 0.818181818181818, 0.909090909090909,
1, NA, NA, NA, NA, NA, NA, -14.571209, -13.829402, -22.1283685,
-22.717841, -34.8053215, 12.988246, 10.2528335, 9.47791, 24.585605,
NA, NA, NA, NA, NA, NA, NA), .Dim = c(11L, 3L), .Dimnames = list(
NULL, c("qhat", "lower", "upper"))), crit =
0.611274541966673,
numsig = 0L, pc = NA), .Names = c("m", "crit",
"numsig",
"pc"))
> xlsFile <- odbcConnectExcel("file.xls", readOnly=F)
> for (i in 1:4){
sqlSave(xlsFile, as.data.frame(test[[i]]), tablename="test",
rownames=F,
addPK=T, append=T)
}
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test,
: missing columns in 'data'
> odbcCloseAll()
I've tried different combination and the 1st element is always exported
but the next ones never. Elements 2 and 3 have the same number of
columns; the problem persists in that case.
Thanks a lot for your help
Ivan