[R] sourcearg function is there a better way already built into R
Robert Sandefur
RSandefur at cam-llc.com
Tue Mar 6 21:22:41 CET 2012
List and Jim
-----Original Message-----
From: jim holtman [mailto:jholtman at gmail.com]
Sent: Tuesday, March 06, 2012 09:47
To: Robert Sandefur
Cc: r-help at r-project.org
Subject: Re: [R] sourcearg function is there a better way already built into R
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