[R] Dynamic file / url name with read.csv

Kevin Middleton kmm at csusb.edu
Wed Jan 13 07:25:17 CET 2010


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:
> 
> 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. 
> 
> 
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list