I am trying to rewrite some code using the sqldf library in R, which should allow me to run SQL queries in data frames, but I have a problem in that whenever I try to run a query, R seems to try to query the actual actual MySQL db con, which I use, and look for the table by the name of the data frame that I'm trying to execute.
When I ran this:
sqldf("SELECT COUNT(*) from work.class_scores")
I get:
Error in mysqlNewConnection (drv, ...): RS-DBI driver: (Could not connect to the database: Error: cannot connect to the local MySQL server through the socket "/tmp/mysql.sock" (2))
When I try to specify a location using two different methods (the first form is googlecode page, the second is correct based on documents)
> sqldf("SELECT COUNT(*) from work.class_scores", sqldf.driver = "SQLite") Error in sqldf("SELECT COUNT(*) from work.class_scores", sqldf.driver = "SQLite") : unused argument(s) (sqldf.driver = "SQLite") > sqldf("SELECT COUNT(*) from work.class_scores", drv = "SQLite") Loading required package: tcltk Loading Tcl/Tk interface ... Error : .onLoad failed in loadNamespace() for 'tcltk', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared library '/Library/Frameworks/R.framework/Resources/library/tcltk/libs/x86_64/tcltk.so': dlopen(/Library/Frameworks/R.framework/Resources/library/tcltk/libs/x86_64/tcltk.so, 10): Library not loaded: /usr/local/lib/libtcl8.5.dylib Referenced from: /Library/Frameworks/R.framework/Resources/library/tcltk/libs/x86_64/tcltk.so Reason: image not found Error: require(tcltk) is not TRUE
So, I think this may be a problem with the tcltk package that I have never heard of, so I try to take care of this and find some problems:
> install.packages("tcltk") Warning in install.packages : argument 'lib' is missing: using '/Users/michaeldiscenza/Library/R/2.11/library' Warning in install.packages : package 'tcltk' is not available > install.packages("tcltk2", lib="/Applications/RStudio.app/Contents/Resources/R/library") trying URL 'http://lib.stat.cmu.edu/R/CRAN/bin/macosx/leopard/contrib/2.11/tcltk2_1.1-5.tgz' Content type 'application/x-gzip' length 940835 bytes (918 Kb) opened URL ================================================== downloaded 918 Kb The downloaded packages are in /var/folders/Y1/Y1gdz9tKFiSnWsGP9+BDcU+++TI/-Tmp-//RtmpL07KTL/downloaded_packages > library("tcltk") Loading Tcl/Tk interface ... Error : .onLoad failed in loadNamespace() for 'tcltk', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared library '/Library/Frameworks/R.framework/Resources/library/tcltk/libs/x86_64/tcltk.so': dlopen(/Library/Frameworks/R.framework/Resources/library/tcltk/libs/x86_64/tcltk.so, 10): Library not loaded: /usr/local/lib/libtcl8.5.dylib Referenced from: /Library/Frameworks/R.framework/Resources/library/tcltk/libs/x86_64/tcltk.so Reason: image not found Error: package/namespace load failed for 'tcltk'
A mistake in! dbPreExists: invalid argument type
Here I just donβt know what the problem is, do I need to move something?
Another approach I tried was before starting the query in the data frame object, establishing my database connection so that R looked there rather than trying to connect to the actual local MySQL database. But that did not work. Let's get back to the problem with the socket (even if I can query the local database myself without any problems.
> con <- sqldf() Error in mysqlNewConnection(drv, ...) : RS-DBI driver: (Failed to connect to database: Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) )
In the end, I want to query to get the number of entries where the C value is greater than 2, for example, and I feel comfortable. The only problem is that I don't know if there is another way to indicate that what I'm requesting is a data frame, not the actual db. Did I miss something really stupid and easy here?
Thanks!