Data Science

Connect RStudio to an access database (x64 bit)

When working with larger datasets you are frequently confronted with an access database. In this post, I will show you that it is very easy to connect RStudio to different databases.

First you need to load the required package/ install it when you don’t have it yet.


In a next step you neet to set up the connection to your database. This can be done in one line of code:

con<-odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:/Users/lliebi/Dropbox/Daten Luca/PhD/other Projects/Run python in R/Test.accdb")

Notice for your purpose you just need to change the path to your file. Simply replace the string after (DBQ= ) with your specific file path.

Having connected to the database you will see the connection in the global environment. 

If you want to read data from the database use sqlFetch:

data <- sqlFetch(con, "Tabelle1")

You can also write into the database (e.g. after having done some analysis). This could also be very helpful when your crawling data from the web, save it in the database and at the same time read it from it.

sqlSave(con,as.data.frame(test), tablename="Table2")

I remember when I worked the first time with access databases and it took me quite a while to access the data. However, I hope that this small tutorial will help you when you are confronted with such a problem.



Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.