Created
February 20, 2014 09:06
-
-
Save qoelet/9109654 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RMySQL) | |
library(GetoptLong) | |
# had to work with a secure connection to a MySQL | |
# make a option file, e.g. opts.cnf | |
" | |
[client] | |
user=kenny | |
host=mysqldb | |
ssl-ca=ca.crt | |
ssl-cert=cert.crt | |
ssl-key=mykey.key | |
" | |
# other assignments | |
# e.g. df_name = "extraction_{{country}}" | |
# run query multiple times across different country tables | |
countries = c("singapore", "malaysia", "thailand") | |
for (country in countries) { | |
country_query = qq(query, code.pattern="\\{\\{CODE\\}\\}") | |
country_df_name = qq(df_name, code.pattern="\\{\\{CODE\\}\\}") | |
con = dbConnect(MySQL(), user="kenny", dbname=db, host="mysqldb", default.file="opts.cnf") | |
tmp_df = dbGetQuery(con, country_query) | |
assign(country_df_name, tmp_df) | |
dbDisconnect(con) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment