Skip to content

Dynamic file / url name with read.csv

3 messages · B S, Kevin Middleton, ivan popivanov

B S
#
Hi- 

I would like to be able to change the value of SymA below and download a file from the corresponding URL.? Hardcoded, this line works fine: 

Symbol<- read.csv("http://ichart.finance.yahoo.com/table.csv?s=SPY&ignore=.csv", stringsAsFactors=F)

However, when I incorporate using?a variable for the ticker, it no longer works.? 

SymA<- "SPY"
Sym1<- cat('http://ichart.finance.yahoo.com/table.csv?s=",SymA,"&ignore=.csv",sep="";)
Symbol<- read.csv(Sym1, stringsAsFactors=F)

I know that the problem lies in the concatenation, but I've tried different variations of cat() and toString() (and others) with SymA and Sym1 but cannot seem to get a string together that will work.? Would appreciate any suggestions for this simple problem?? 

Thank you.
#
A few suggestions:
  Don't mix ' and "
  Use paste()
  Don't include an extraneous ;

SymA<- "SPY"
Sym1<- paste("http://ichart.finance.yahoo.com/table.csv?s=",SymA,"&ignore=.csv",sep="")
Symbol<- read.csv(Sym1, stringsAsFactors=F)
On Jan 12, 2010, at 10:03 PM, B S wrote: