[R] sqlFetch (RODBC) question

Kenn Konstabel lebatsnok at gmail.com
Thu Mar 3 15:55:52 CET 2011


Dear all,

I've used RODBC a lot to read in files created in MS excel and access but
found a strange problem today: a variable in my data file contained both
numbers and text; sqlFetch would set text within a row of numbers to NA; but
if first 5 or 6 rows would be text then all numbers would be read in as NA.

con<-odbcConnectExcel("xample.xls")   #the file is attached or at
http://psych.ut.ee/~nek/ajutine/xample.xls
sqlFetch(con, "TT$")
#     ID_NO Setting_ID
#1       NA         NA
#2  1220000      12203
# 3  1220001      12203
#etc

Whereas the same file saved as csv reads in correctly as:

read.csv("xample.csv")
#     ID_NO Setting_ID
#1        b          a
#2  1220000      12203
#3  1220001      12203
#4  1220002      12202
#5  1220003      12202
#etc

Can anyone explain why it would behave like this?

#just in case:
> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] RODBC_1.3-2

loaded via a namespace (and not attached):
[1] iterators_1.0.3 tools_2.12.1



Thanks in advance,
Kenn

Kenn Konstabel
Department of Chronic Diseases
National Institute for Health Development
Hiiu 42
Tallinn, Estonia


More information about the R-help mailing list