The following links may help navigating this page
No Feed Found

Database Connectivity with R · 2006-02-23

There was one thing missing for fully automated dataprocessing with R here on my machine: Database Connectivity. R actually has it for some databases. I tried it with MySQL.

One needs to download Bell Labs's R libraries DBI and RMySQL and then follow the instructions at R Data Import/Export.

To test it I used the access logs I was exploring lately. I created a view, 'hitsperminute' on the database containing the hits per minute on free-penguin, as the name suggests. Adding database connectivity to R was no fuzz at all. It just worked. Consider the following code:


library(RMySQL)
con <- dbConnect(dbDriver("MySQL"), dbname = "webstats", password="*****", username="dbuser")
a <- dbGetQuery(con, paste("SELECT * FROM hitsperminute;"))
plot(a[,1],
  col.sub="#555555",
  axes=FALSE, type="n",
  main="Free Penguin News Quake",
  xlab="Minutes",
  ylab="Requests",
  sub="free-penguin.org requests per minute from Jan 2nd to Jan 8th 2006")
axis(1, label=FALSE)
axis(2)
points(a[,1],
  pch=20,
  col="#dddddd",
  cex=.1)
lines(
  smooth.spline(a[,1]),
  col="#dd0000")
dbDisconnect(con)

the result is this recent one, but skipping manual steps. Scripts like this are fully batch mode enabled. One could run it on http requests for example. Cool, ain't it?


Commenting is closed for this article.