[R] SQL Queries from Multiple Servers

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Thu May 14 04:49:19 CEST 2009

Tom Schenk Jr wrote:
> I use RODBC as my conduit from R to SQL. It works well when the tables are
> stored on one channel, e.g.,
> channel <- odbcConnect("data_base_01", uid="....", dsn="....")
> However, I often need to match tables across multiple databases, e.g.,
> "data_base_01" and "data_base_02". However, odbcConnect() appears limited
> insofar as you may only query from tables within a single channel, e.g.,
> database. I do not have access to write and create new tables on the SQL
> servers, which is a possible solution (e.g., copy all tables into a single
> database).
> Is there any way, in RODBC or another R-friendly SQL package, to perform SQL
> operations across multiple databases?

Sounds like you want... a SQL database engine.  Some engines provide
features to work with external tables... but it is not standardized and
it is not usually very efficient. You usually have to have some level of
admin privilege to do this.

Alternatively, you can create a new database using an engine of your
choice, move the data to that common working database, and do your
cross-queries to your heart's content. Depending on your working
environment, SQLite, MySQL, MS Jet, or MSDE could be options. Or, if your
joins are fairly small you can use R's merge function and doBy.
It seems a bit much to me to expect a database access library to
do double duty as a SQL database engine, though.

Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k

More information about the R-help mailing list