----- Forwarded message from Dean Adams ----- Date: Tue, 26 Jun 2012 13:26:54 -0400 From: Dean Adams Reply-To: Dean Adams Subject: Re: reading nts file format in R: addendum To: morphmet@morphometrics.org
Folks, Sorry. Neglected to include a second function required by my readland.nts file. Both functions are below. Dean -- Dr. Dean C. Adams Associate Professor Department of Ecology, Evolution, and Organismal Biology Department of Statistics Iowa State University Ames, Iowa 50011 www.public.iastate.edu/~dcadams/ phone: 515-294-3834 #function required by readland.nts arrayspecs<-function(A,p,k,byLand=T){ names<-rownames(A) n<-length(unlist(A))/(p*k) if(byLand==T){ n.m<-NULL for(i in 1:n){ temp<-as.matrix(A[((1+(i-1)*p):(i*p)),1:k]) n.m<-cbind(n.m,temp)} specimens<-array(n.m,dim=c(p,k,n)) } if(byLand==F){ n.m<-NULL for(i in 1:n){ temp<- matrix(A[i,],ncol=k,byrow=T) n.m<-cbind(n.m,temp)} specimens<-array(n.m,dim=c(p,k,n)) } dimnames(specimens)[[3]]<-names return(specimens) } #read landmark data from NTS file readland.nts<-function(file){ ntsfile<-scan(file=file,what="char",quote="",sep="\n",strip.white=T,comment.char="\"",quiet=T) header<-unlist(strsplit(ntsfile[1]," ")) if(header[1]!=1){ stop("NTS file not a rectangular matrix. First value in parameter line must be '1'.") } header<-casefold(header,upper=T) dimval<-unlist(grep("DIM=",header)) if(length(dimval)==0){ stop("Header does not contain 'DIM=' designator.") } labval<-unlist(grep("L",header)) r.lab<-ifelse(is.element("2",labval)==T,T,F) c.lab<-ifelse(is.element("3",labval)==T,T,F) header<-sub("L","",header) header<-as.numeric(sub("DIM=","",header)) missdata<-ifelse(header[4]!=0,T,F) if(missdata==T){missval<-ifelse(dimval==6,header[5],header[6]) } n<-header[2];k<-header[dimval];p<-header[3]/k; tmp<-gsub("\\t"," ",ntsfile[-1]) #replace tabs with spaces tmp<-unlist(strsplit(tmp,split=" +")) speclab<-NULL; if(r.lab==T){ speclab<-tmp[1:n] tmp<-tmp[-(1:length(speclab))] } if(c.lab==T){ tmp<-tmp[-(1:(p*k))] } if(missdata==T){tmp<-sub(missval,"-999",tmp)} landdata<-matrix(as.numeric(tmp),ncol=k,byrow=T) coords<-arrayspecs(landdata,p,k,byLand=T) dimnames(coords)[[3]]<-speclab return(coords=coords) } On 6/26/2012 11:35 AM, morphmet_modera...@morphometrics.org wrote: > ----- Forwarded message from ppi...@uniroma3.it ----- > > Date: Tue, 19 Jun 2012 06:42:52 -0400 > From: ppi...@uniroma3.it > Reply-To: ppi...@uniroma3.it > Subject: reading nts file format in R > To: morphmet@morphometrics.org > > Hi folks, > someones knows if exists a code to read nts files in R? > Thankyou > Paolo > ----- End forwarded message -----