[R] Import of Access data via RODBC changes column name ("NO" to "Expr1014") and the content of the column

Dieter Menne dieter.menne at menne-biomed.de
Tue Aug 14 18:06:57 CEST 2007


Maciej Hoffman-Wecker <Maciej.Hoffman-Wecker <at> bioskin.de> writes:

...
> But I succeeded in developing a tiny example, that reproduces the bug
(wherever it is).
> 
> I generated a small Access data base "test2.mdb" with one table "Tab1" and
following columns:
..... 

> > library(RODBC)
> > .con <- odbcConnectAccess("./test2.mdb")
> > (.d <- try(sqlQuery(.con, "select * from Tab1")))

> > (.d <- try(sqlQuery(.con, "select F1 , NO , F2 from Tab1")))
>   F1 Expr1001 F2
> 1  1        0  1
> 2  2        0  2
> 3  0        0  1
> 4  1        0  0
> > close(.con)

NO is a reserved word in ODBC (or where...). Whenever you see Exprxxx in
columns, put the column name in []
d <- try(sqlQuery(con, "select F1 ,[NO], F2 from Tab1"))

works for me.

Dieter



More information about the R-help mailing list