[R] Macro variable substitution
Erik Iverson
eiverson at NMDP.ORG
Tue Sep 29 20:22:38 CEST 2009
One option, see ?assign and write a wrapper around it, using the "pos" argument.
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of David Young
> Sent: Tuesday, September 29, 2009 10:58 AM
> To: r-help at r-project.org
> Subject: [R] Macro variable substitution
>
> Hello All,
>
> I'm a new R user and have a question about what in SAS would be called
> macro variable substitution. Below is some R code that doesn't work,
> but I think it will illustrate what I'd like to do.
>
> readfunc<-function(x) {
> x <<- read.table(paste(x,".csv",sep=""), header=TRUE,sep=",")
> }
> readfunc(TEF)
>
> What I'd like to do is have the letters "TEF" become the name of the new
> R data and also be used in conjunction with ".csv" to read the file
> "TEF.csv".
>
> So working R code looks like this:
>
> TEF <- read.table(TEF.csv, header=TRUE,sep=",")
>
> but I'd like to type the changing letter sequence just once.
>
> Any suggestions would be appreciated.
>
> --
> Best regards,
>
> David Young
> Marketing and Statistical Consultant
> Madrid, Spain
> +34 913 540 381
> http://www.linkedin.com/in/europedavidyoung
>
> ______________________________________________
> 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