Re: [R] Macro variable substitution
There was a rather in depth article on doing macros in R in the R newsletter a couple of years ago. There is also the defmacro function in the gtools package based on that article that can make the job easier for many cases. See fortune(236) before taking the assign route. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of David Young Sent: Tuesday, September 29, 2009 9:58 AM To: r-help@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@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. __ 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.
Re: [R] Macro variable substitution
Hi, I guess you want ?assign See also this page for a working example, http://wiki.r-project.org/rwiki/doku.php?id=guides:assigning-variable-names HTH, baptiste 2009/9/29 David Young dyo...@telefonica.net: 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@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. __ 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.
Re: [R] Macro variable substitution
One option, see ?assign and write a wrapper around it, using the pos argument. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Young Sent: Tuesday, September 29, 2009 10:58 AM To: r-help@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@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. __ 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.