[R] SAS Macro Variable in R

David Huffer David.Huffer at csosa.gov
Tue Jun 23 20:50:02 CEST 2009


On Tuesday, June 23, 2009 1:40 PM, 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...

How about something like:

  download.ichart <- function ( symbol , destpath = 'c:/projects/stock data/data/' ) {
    url <- paste (
      "http://ichart.yahoo.com/table.csv?s="
      , substitute ( symbol )
      , ".MC&a=00&b=1&c=2003&d=05&e=23&f=2009&g=d&ignore=.csv"
      , sep = ""
    )
    destfile <- paste ( destpath , substitute ( symbol ) , ".csv" , sep = "" )
    download.file ( url , destfile , quiet = TRUE )
  }

  download.ichart ( "TEF" )


--
 David
 
 -----------------------------------------------------
 David Huffer, Ph.D.               Senior Statistician
 CSOSA/Washington, DC           david.huffer at csosa.gov




More information about the R-help mailing list