I am looking to read a .tps file into R.
An example file is now available at:
example file
The actual files I am trying to read into R obviously have many more individuals/IDs (>1000)
The .tps file format is produced by TPSDIG.
http://life.bio.sunysb.edu/morph/
The file is an ANSI plain text file.
The file contains X and Y coordinates and specimen information as follows.
The main difficulty is that specimens vary in the numbers of attributes (eg. some have 4 and some have 6 LM landmarks, some have 2 curves, others none, with thus no associated points).
I have tried working with a for loop and read.table, but can not find a way to account for the varying number of attributes.
Example of start of file
LM=3
1 1
2 2
3 3
CURVES=2
POINTS=2
1 1
2 2
POINTS=2
1 1
2 2
IMAGE=COMPLETE/FILE/PATH/IMAGE
ID=1
SCALE=1
LM=3
1 1
2 2
3 3
CURVES=2
...
Example dummy code that works if all specimens have equal number of attributes.
i<-1
landmarks<-NULL
while(i < 4321){
print(i)
landmarks.temp<-read.table(file="filepath", sep=" ", header=F, skip=i, nrows=12, col.names=c("X", "Y"))
i<-i+13
landmarks.temp$ID<-read.table(file="filepath", sep=c(" "), header=F, skip=i, nrows=1, as.is=T)[1,1]
i<-i+1
landmarks.temp$scale<-read.table(file="filepath", sep=c(" "), header=F, skip=i, nrows=1, as.is=T)[1,1]
i<-i+2
landmarks<-rbind(landmarks, landmarks.temp)
print(unique(landmarks.temp$ID))
}