Tuesday, October 6, 2015

How do you access data using ODBC data connectivity in R?

R language is well suited for statistics and graphics. R is also good at handling data, perhaps not in large-scale. In order to connect to an ODBC source, it needs an ODBC connector which is found in a library called RODBC.

When you install a number of packages are available out of the box shown here:
 

Installed Packages.png

However you may not find the RODBC in the list. You need to install this library.
You can find RODBC library download here for WIndows.
https://cran.r-project.org/web/packages/RODBC/index.html

You will be downloading a zip file named RODBC_1.3-12.zip

You can download it to a location of your choice but move this file to the( library folder) in the folder created by the R installation.
 

The zip file from the download location(desktop) was moved to the folder C:\Program Files\R\R-3.2.2\library.

librarywithRODBC

 

 
Now if you bring up the installed packages from R-GUI you will see RODBC as shown.

LoadPackages2

Now you are ready to use the RODBC library in working with R.
In the RGUI(64-bit) just type library (RODBC) at the prompt as shown. You get another prompt but nothing else.
--------
> library(RODBC)
>
---------
For help with RODBC you can type the following at R prompt:
----------
>help(package=RODBC)
---------
This will open up the help file in HTML at : http://127.0.0.1:27629/library/RODBC/html/00Index.html as shown:


RODBCDoc.png

Now you can use this help file to explore RODBC further.

There are two groups of functions in RODBC, The internet odbc* commands implement low-level access to ODBC functions and the sql* functions operate at a higher level to read, save, copy etc. You can connect to hosts or DSNs.

Happy data hunting!

No comments: