sobota, 11 lutego 2012

R and MySql

First thing I was trying to do with R was to load data from database. I encountered a few errors :
  • Error: could not find function “sqlQuery”
  • RS-DBI driver
So I installed a two packages RODBC and RMYSQL. Then I run R commander and wrote these few lines:
library(RMySQL) # importing library
m <- MySQL()  # creating connector
con <- dbConnect(m, user='', password='', dbname='') #connection
dbListTables(con) #  all tables from db
dbListFields(con, "tb") # all fields from table
dbGetQuery(con, "query") // printing results
rs <- dbSendQuery(con, "query") // puting results to dataset
d1 <- fetch(rs, n = 10000)
d2 <- fetch(rs, n = -1)
dbDisconnect(con)

R commander with loaded script and few messages in all windows.

Brak komentarzy:

Prześlij komentarz