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.

Reply via email to