Saturday, October 25, 2014

Curl and RCurl getURL

I wanted to use the getURL function from RCurl so I tried to install the RCurl package.  I received this error Cannot find curl-config. In order to clear the error, I had install curl (apt-get install curl).  This didn't work so I ended up trying (libcurl4-gnutls-dev).  I then had to restart R and install R package bitops.  I ran library(RCurl) just to be sure.  getURL is now working.

Friday, October 24, 2014

User Authentication Parameters in .my.cnf

The RMySQL documentation (http://cran.r-project.org/web/packages/RMySQL/RMySQL.pdf) recommends placing user authentication parameters (user, password, database, and host) in the config file. This file is read from $HOME/.my.cnf.  I found this file did not exist so I copied the my.cnf file from /etc/mysql to my home directory and changed ownership (sudo chown...).  Next I added a group and my authentication parameters to the file.  I could then used 'con <- dbConnect(MySQL(), group = "group name")' in R to connect to my database.  This might be more secure if I were to continue using R Studio server from a separate computer, but my plan is to run R scripts locally initiated from PHP files, so I don't think there is any enhancement security in my case, but it does work.

Thursday, October 23, 2014

RMySQL - dbConnect

Now that R was recognizing the dbConnect function, there was a new error.
Error in mysqlNewConnection(drv, ...) : 
  RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'root'@'localhost' (using password: YES)
I concluded this error was returned from MySQL and started looking for a solution in MySQL.  Using MySQL Workbench I had created a database and connected to it from within Workbench.  However I was unable to connect to MySQL from the command line.  I couldn't even start MySQL from the command line.  When you install MySQL you need to create grant tables.  This is easily accomplished in Workbench using the new instance wizard.  I had to select 'Debian' a few steps into the wizard so it would know the correct file paths.  Once the instance was established I was able to create users and assign them access to my database.  I was then able to connect to MySQL from R using my newly created user.

RMySQL Installation Challenges

I loaded RMySQL package so I could connect R to MySQL.  I used the install feature within R Studio.  The package installed without errors, but when I tried to use the dbConnect function I would get this message Error: could not find function "dbConnect".  I finally tried 'library(RMySQL)' and that did the trick.  Also had to run 'library(DBI)'.  DBI was installed with RMySQL as a dependency.

Background

Several months ago I purchased a used computer to use for a hobby machine with the intent of learning more about programming.  Recently I realized that if I didn't start to capture my experience, there was a good chance I would forget what I had done.  So today I am starting this blog to capture my small achievements.  So far I installed Linux Debian, Apache, MySQL, PHP and R Studio Server.  I installed VNC so I can access my machine remotely.  After some research I also installed NetBeans (PHP and others), PyCharm and MySQL Workbench IDEs.