[R-SIG-Finance] RMySQL issue
Josh Ulrich
josh.m.ulrich at gmail.com
Sun Dec 21 18:04:29 CET 2008
Julien,
This question is more appropriate for R-help. You'll usually get
faster/better replies from it, since it's more widely used.
The problem is with your use of the paste() command. Use this instead:
upload_prices_single <- function(ticker, date_start,date_end)
{
Connect <- dbConnect(dbDriver("MySQL"),host="localhost",username="root",password="",dbname="QF_DUMP14122008",port="")
data <- dbGetQuery(Connect,paste("select quote_date, quote_adj_close
from qf_data_yahoo where quote_name = '",ticker,"' and quote_date >
'",date_start,"' and quote_date < '",date_end,"'",sep=""))
return(data)
}
HTH,
Josh
--
http://quantemplation.blogspot.com
On Sun, Dec 21, 2008 at 10:54 AM, julien cuisinier
<j_cuisinier at hotmail.com> wrote:
>
> Hi,
>
>
> As often on this mailing list, my apologies if the question is trivial. I still quite new to R
>
> I am using R 2.8.0 with the cocoa GUI available for free download, so under mac os x (but irrelevant here I believe)
> I try to extract data from a MySQL DB using RMySQL package.
>
> The connection functions fine and I can extract manually without any issue. My aim is to create a R function to "automate" the extraction from my DB
>
> Here is the piece of code I am trying to work out.
>
> upload_prices_single <- function(ticker, date_start,date_end)
>
> {
>
> Connect <- dbConnect(dbDriver("MySQL"),host="localhost",username="root",password="",dbname="QF_DUMP14122008",port="")
>
> data <- dbGetQuery(Connect,paste("select quote_date, quote_adj_close from qf_data_yahoo where quote_name = 'ticker' and quote_date > 'date_start' and quote_date < 'date_end'"))
>
> return(data)
> }
>
>
> If I type the "dbGetQuery" command entering the ticker manually in the console like below functions:
>
> Connect <- dbConnect(dbDriver("MySQL"),host="localhost",username="root",password="",dbname="QF_DUMP14122008",port="")
>
> data <- dbGetQuery(Connect,paste("select quote_date, quote_adj_close
> from qf_data_yahoo where quote_name = 'III.L' and quote_date >
> '2008-11-12' and quote_date < '2008-12-12'"))
>
> So I guess it "only" an issue with assigning correctly "III.L" to a variable "ticker" and passing it on correctly...
>
>
> Any help is appreciated
>
>
> Thanks & regards,
> Julien
>
>
> _________________________________________________________________
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
More information about the R-SIG-Finance
mailing list