?pmatch ?switch _may_ be of use...
But if the file calls it Fe and you want to label it "Iron," then you'll need some sort of explicit dictionary. -- Bert On Tue, Mar 6, 2012 at 12:57 PM, Robert Sandefur <rsande...@cam-llc.com> wrote: > List and Jim: > > My solution works to my satisfaction so perhaps I should not have not ask. > The problem was basically this: > 1. I receive a CSV file containing assays on various chemical elements. The > names of these fields are inconsistent in terms of spelling, length and case. > 2. As an example I would like to do a cumulative frequency on each of the > fields and have the plot labeled with the name of the field as well is > operating on that field. > 3. The reason I wrote sourcearg was to simultaneously have a command that > would do the cum freq and label the plot > i.e. sourcearg generates and sources > vuse=(TCU+0.01-DUPTCU+0.01)/(TCU+0.01+DUPTCU+0.01)/2 > qqnorm(vuse,main=\"Redacted TCUCumFreq > ((TCU+0.01-DUPTCU+0.01)/(TCU+0.01+DUPTCU+0.01)/2)") > > Which gives me what I want but I can't embed the picture because of the > restrictions on the mailing list. > > Thanx > > Bob > > > > > > > > > -----Original Message----- > From: jim holtman [mailto:jholt...@gmail.com] > Sent: Tuesday, March 06, 2012 09:47 > To: Robert Sandefur > Cc: r-help@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 <rsande...@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@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. > > ______________________________________________ > 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ 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.