名称粘贴时,RMySQL中的dbWriteTable错误

时间:2014-07-17 00:05:14

标签: database r stocks rmysql

我有很多data.frames()我试图通过RMySQL()发送到MySQL数据库。

# Sends data frame to database without a problem
dbWriteTable(con3, name="SPY", value=SPY , append=T)

# stock1 contains a character vector of stock names...
stock1 <- c("SPY.A") 

但是当我尝试循环它时:

i= 1
while(i <= length(stock1)){
# converts "SPY.A" into SPY 
name <- print(paste0(str_sub(stock1, start = 1, end = -3))[i], quote=F) 
# sends data.frame to database
dbWriteTable(con3,paste0(str_sub(stock1, start = 1, end = -3))[i], value=name, append=T)
i <- 1+i
}

返回以下警告&amp;没有发送到数据库

In addition: Warning message:
In file(fn, open = "r") :
cannot open file './SPY': No such file or directory

但是,我认为问题在于将value粘贴到dbWriteTable(),因为编写dbWriteTable(con3, "SPY", SPY, append=T)有效,但dbWriteTable(con3, "SPY", name, append=T)不会...... {/ p>

1 个答案:

答案 0 :(得分:1)

您可能正在使用str_sub的非基础包,并且我猜测您与substr的行为相同。这会成功吗?

dbWriteTable(con3,  substr( stock1, 1,3) , get(stock1),  append=T)