0

I m relatively new to R. I m using the RMySQL Library to get some data and then process it in R. My code looks something like this.

arg<-commandArgs(TRUE)    

rs<-dbSendQuery(con, "select owner_name, domain, count(*) as freq from playlist 
where DATE(time_last_update) between arg[1] AND arg[2] group by owner_name;")

d<-fetch(rs, n=0)
d$test<-apply(d,1,function(row) 1)
dp<-ddply(d, .(test), transform, percentile=ecdf(freq)(freq))
write.csv(dp, file="/usr/monthly_analytics/viewer_data/playlist.csv")

I m pretty much sure this is incorrect. I m calling R with the following parameters.

 Rscript test.R 2013-06-25 2012-12-25

As expected the MySQL server is returning error with query. What is the correct way to pass an argument inside the SQL statement from R?

Thank you in advance.

m_amber
  • 747
  • 3
  • 13
  • 23
  • I can't test it right now, so I don't put it as an answer but I guess if you try `rs <- dbSendQuery( con, paste( "SELECT owner_name, domain, count(*) AS freq FROM playlist WHERE DATE(time_last_update) BETWEEN", arg[1], "AND", arg[2], "GROUP BY owner_name;" ) )` you are a step closer. – vaettchen Jun 25 '13 at 10:31
  • Possibly look here? http://stackoverflow.com/questions/4290672/how-to-add-a-dynamic-value-into-rmysql-getquery - as vaettchen points out, `paste` (or `sprintf`) are good ways to go. – BenBarnes Jun 25 '13 at 10:31
  • @vaettchen , the paste command worked, thanks. – m_amber Jun 25 '13 at 11:21

0 Answers0