Using RMySQL I want to load data from a database into a dataframe in R. For this I’m using the following code:
Rconnectdb:
con <- dbConnect(MySQL(),
user="root", password="password",
dbname="prediction", host="localhost")
Main code
library(RMySQL)
source("Rconnectdb") #load the database connection
query = "select received,isRefound from message" #specify query
rs=dbGetQuery(con,query) #resultset
dataset <- fetch(rs, n=-1) #fill dataset with all rows of the resultset
dbClearResult(rs) #clear resultset
Executing this I get the following error
Error in function (classes, fdef, mtable) : unable to find an
inherited method for function “fetch”, for signature “data.frame”,
“numeric”
Any ideas?
You’re mistaking
dbSendQuerywithdbGetQuery.dbGetQuerycombinedbSendQuery,fetchanddbClearResultas per documentation:From
?dbGetQueryin packageDBI.