[R] Reading Text Files with RODBC

Gabor Grothendieck ggrothendieck at gmail.com
Thu Feb 16 19:15:21 CET 2012


On Thu, Feb 16, 2012 at 10:12 AM, Nutter, Benjamin <NutterB at ccf.org> wrote:
> I'm thoroughly stumped.  I've been playing with RODBC and wanted to see if I could retrieve data from text files using this package as well (for the most part, this is an intellectual exercise, but occasionally I do get data files large enough in CSV format RODBC could be helpful) .
>
> I set up a DNS called "Text Files" and then ran the following code in R
>
>> library(RODBC)
>> mtg <- odbcConnect("Text Files")
>> sqlTables(mtg)
>                         TABLE_CAT TABLE_SCHEM    TABLE_NAME  TABLE_TYPE        REMARKS
> 1 C:\\USERS\\NUTTERB                   <NA>    Core2012.txt              TABLE                 <NA>
> 2 C:\\USERS\\NUTTERB                   <NA> MTGCards.csv              TABLE                 <NA>
>> sqlFetch(mtg, "MTGCards.csv")
> Error in odbcTableExists(channel, sqtable) :
>  'MTGCards.csv': table not found on channel
>>
>
> MTGCards.csv is an export from an MS Access database, and I'm able to get it out of Access, and I'm also able to connect to our Oracle databases.  So I'm not sure what it is I'm not getting about reading the text files.  If anyone has done this successfully and has any pointers, I'd appreciate it.  So far I've not been able to solve it with documentation from RODBC, RStudio (I get the same error messages when I use the RGui), or Microsoft ODBC drivers.
>

This isn't precisely what you are asking for but if the idea is to
apply an sql statement to a csv file then read.csv.sql in the sqldf
package can apply an sql statement to a csv file reading the result
into R.  If you omit the sql statement then it reads it all in.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list