For all the people out there who want to create Perl hashes out of their R lists:

# convert a R list into a Perl hash list2hash<-function(data,firstcall=TRUE) { output<-''

if(is.list(data)) { if(length(names(data)) > 0) { output<-"{\n" for(i in names(data)) { key<-i # value<-data$i value<-eval(parse(text=paste("data",i,sep="$"))) output<-paste(output,key," => ",list2hash(value,FALSE),"\n",sep='') } output<-paste(output,"},\n",sep='') } else { # make me a vector output<-"[\n" for(i in data) { output<-paste(output,list2hash(i,FALSE),"\n",sep="") } output<-paste(output,"],\n",sep='') } } else { if(is.vector(data) && length(data) > 1) { # I am a vector output<-"[\n" for(i in data) { output<-paste(output,list2hash(i,FALSE),"\n",sep="") } output<-paste(output,"],\n",sep='') } else { # I'm not a couth vector (where couth>1), nor a list - so I must be a single value output<-paste("'",data,"',",sep='') } } if(firstcall) { # if you wanted to prefix the output with '$VAR=' # myoutput<-paste("$",substitute(data),"=",substr(output,0,nchar(output)-2),";\n",sep='') myoutput<-paste(substr(output,0,nchar(output)-2),";\n",sep='') return(cat(myoutput)) } else { return(output) } }

If you'd like to check the validity of an email address, use this function:

validemail<-function(address) length(grep("^[\\w!#\\$%&'*+\\-\\/=?^`{|}~][\\w!#\\$%&'*+\\-\\/=?^`{|}~.]{0,62}[\\w!#\\$%&'*+\\-\\/=?^`{|}~]{1}@([\\w\\d\\-]+\\.)+[\\w\\d\\-]+$",address,perl=TRUE))
Edit | Attach | Print version | History: r3 < r2 < r1 | Backlinks | View wiki text | Edit WikiText | More topic actions...
Topic revision: r2 - 06 Jun 2007, ColeBeck
 

This site is powered by FoswikiCopyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback