[R] sourcearg function is there a better way already built into R

jim holtman jholtman at gmail.com
Tue Mar 6 17:47:08 CET 2012


The basic question is what do you want the function to do.  It seems
convoluted and I am not sure exactly what you are giving it as input
and what you expect as output. Not exactly sure of what the 'sink' and
'source' are supposed to do.  So "tell me what you want to do, not how
you want to do it".

On Tue, Mar 6, 2012 at 10:29 AM, Robert Sandefur <RSandefur at cam-llc.com> wrote:
> Hi list:
>
>
>
> I work with a lot of laboratory analytical data and I often have
> inconsistent names of files and variables within those files so I wrote
> this sourcearg function to facilitate handling file and variable names
> as both character and R names. The source of the function is given below
>
>
>
> sourcearg=function(arg){
>
> su=sprintf("%s\n",arg)
>
> sink("TMPTMPRarg")
>
> printf("%s\n",arg) # printf = cat(sprintf(....))
>
> sink()
>
> source("TMPTMPRarg")
>
> return(su)
>
> }
>
>
>
> A trival invocation is given below but the next time I get data the
> names of assays might be Mg,MN,and Fe
>
> asyl=c("MG","MN")
>
> for(asy in asyl){
>
> j=read.csv(sprintf("%sDUPS.csv",asy),head=T)
>
> attach(j)
>
> printf("plot(%s,DUP%s,log=\"xy\")",asy,asy)
>
> sourcearg(sprintf("plot(%s+0.01,DUP%s+0.01,log=\"xy\",main=\"Redacted
> %s\nOrg Log+0.01 vs Dup Log+0.01 Plot\" )",asy,asy,asy))
>
> print(names(j))
>
> ipsend()
>
> detach(j)
>
> }
>
>
>
> A more typical invocation would use tapply to get the names of all the
> variables in the CSV file into asyl and then do the for loop.
>
>
>
> sourcearg works fine for my purposes but my question is:  is there a
> better way to do this in R that is already built-in?
>
>
>
> Thanx
>
>
>
> Robert (Bob) L. Sandefur PE
>
>
>
> Senior Geostatistician / Reserve Analyst
>
>
>
> CAM
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list