RMySQL fetch - 找不到继承的方法

dee*_*mel 2 mysql r rmysql

使用RMySQL我想将数据从数据库加载到R中的数据帧.为此,我使用以下代码:

Rconnectdb:

con <- dbConnect(MySQL(),
user="root", password="password",
dbname="prediction", host="localhost")
Run Code Online (Sandbox Code Playgroud)

主要代码

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
Run Code Online (Sandbox Code Playgroud)

执行此操作我收到以下错误

函数错误(classes,fdef,mtable):无法找到函数"fetch"的继承方法,签名"data.frame","numeric"

有任何想法吗?

pla*_*pus 5

你错dbSendQuerydbGetQuery.
dbGetQuery结合dbSendQuery,fetchdbClearResult根据文件:

该函数dbSendQuery仅提交并同步执行SQL语句到数据库引擎.它不会提取任何记录 - 因为您需要使用该功能fetch(确保dbClearResult在完成获取所需记录时调用).

该函数dbGetQuery在一个操作中完成所有这些操作(提交语句,获取所有输出记录,并清除结果集).

?dbGetQuery包中DBI.