[R] dbApply (R newbee)

David James dj at research.bell-labs.com
Tue Jul 15 15:36:35 CEST 2003


Hello Jesper,

My mistake.  I should have replaced the call to dbGetConnection(res)
with as(res, "MySQLConnection").  Thus, the easiest workaround is
for you to define the following trivial function

   dbGetConnection <- function(res) as(res, "MySQLConnection")

and re-run your example.

Thanks for the report.

--
David


Jesper Runge Madsen wrote:
> I am trying to use R interfaced with MySQL. Present goal is that R should
> calculate the 85% quantile of AvgSpeed for each LinieID. Looking through
> documentation of the RMySQL Package, I guessed that dbApply would do the
> trick due to this example
> 
>  
> 
> ## compute quanitiles for each network agent
> con <- dbConnect(MySQL(), group="vitalAnalysis")
> res <- dbSendQuery(con, 
              "select Agent, ip_addr, DATA from pseudo_data order by Agent")
> out <- dbApply(res, INDEX = "Agent", 
>         FUN = function(x, grp) quantile(x$DATA, names=FALSE))
>  
> 
> But when I try I get this:
> 
>  
> 
> > con = dbConnect(MySQL(),group="Speed")
> 
> > res <- dbSendQuery(con, "Select LinieID, AvgSpeed from speedlinietur order
> by LinieID, AvgSpeed")
> 
> > out <- dbApply(res, INDEX = "LinieID",FUN = function(x, grp)
> quantile(x$AvgSpeed, names=FALSE))
> 
> Error in mysqlDBApply(res, ...) : couldn't find function "dbGetConnection"
> 
> >
> 
>  
> 
> I saw in an earlier posting that:
> 
> There has been a change in function names in the new RMySQL 0.5-0 
> version (also in the new ROracle and RSQLite). The reason is that 
> the R-SIG-DB has agreed on a common interface to all databases, 
> and as part of this new common interface, most functions have been 
> renamed. The following simple name mapping may help you upgrade 
> existing code to the new DBI: 
> 
> pre-DBI DBI 0.1-4 
> 
> 
..
> 
> dbGetConnection = getConnection
> 
> 
..
> 
>  
> 
>  
> 
> when I do this I get this error message
> 
> > dbGetConnection = getConnection
> 
> > out <- dbApply(res, INDEX = "LinieID",FUN = function(x, grp)
> quantile(x$AvgSpeed, names=FALSE))
> 
> Error in if (what %in% set) structure(what, class = "connection") else NULL
> : 
> 
>         argument is of length zero
> 
> >
> 
>  
> 
> Can anyone please help me
> 
>  
> 
>  
> 
>  
> 
>  
> 
> Jesper Runge Madsen
> 
> Ph.D.
> 
> Trafikforskningsgruppen
> 
> Institut for Samfundsudvikling og Planlægning
> 
> Aalborg Universitet
> 
>  <mailto:runge at plan.auc.dk> runge at plan.auc.dk
> 
>  
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
David A. James
Statistics Research, Room 2C-253            Phone:  (908) 582-3082       
Bell Labs, Lucent Technologies              Fax:    (908) 582-3340
Murray Hill, NJ 09794-0636




More information about the R-help mailing list