0

i have many data.frames() that i am trying to send to MySQL database via RMySQL().

# 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") 

But when I try to loop it:

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
}

The following warning is returned & nothing was sent to database

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

However, I believe that the problem is with pasting value onto dbWriteTable() since writing dbWriteTable(con3, "SPY", SPY, append=T) works but dbWriteTable(con3, "SPY", name, append=T) will not...

Rime
  • 912
  • 2
  • 11
  • 39
  • I can't recreate an example of this on my system, but I have run into similar situations and have used 'eval(name)' instead of just 'name' in an argument and it worked. Maybe that can help? – nfmcclure Jul 17 '14 at 00:09
  • Thanks, @nfmcclure but `eval(name)` that did not work for this – Rime Jul 17 '14 at 00:18

1 Answers1

1

You are probably using a non-base package for str_sub and I'm guessing you get the same behavior with substr. Does this succeed?

dbWriteTable(con3,  substr( stock1, 1,3) , get(stock1),  append=T)
IRTFM
  • 258,963
  • 21
  • 364
  • 487