On Tue, 23 Jun 2009, David Young wrote:

Hi I'm new to R and would like to implement a SAS-like macro variable
in R.

What I'd like to do is take the simple R code below and change the
"=TEF" to different letters to refer to different companies' data for
download.

# DOWNLOADS FILES FROM YAHOO INTERNET
download.file('http://ichart.yahoo.com/table.csv?s=TEF.MC&a=00&b=1&c=2003&d=05&e=23&f=2009&g=d&ignore=.csv',
'c:\\projects\\stock data\\data\\test.csv',quiet=TRUE)

As you can see the text I want to change is within the quoted Internet
address.  Is this possible in R?

I do this sort of  thing with sub() or gsub()

download.file(sub('TEF','http://ichart.yahoo.com/table.csv?s=TEF.MC&a=00&b=1&c=2003&d=05&e=23&f=2009&g=d&ignore=.csv',thing_to_sub_for_TEF),
 'c:\\projects\\stock data\\data\\test.csv',quiet=TRUE)

I would also use forward slashes / rather than double backslashes \\, but 
that's just a matter of taste.

     -thomas

Thomas Lumley                   Assoc. Professor, Biostatistics
tlum...@u.washington.edu        University of Washington, Seattle

______________________________________________
R-help@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.

Reply via email to