----- Forwarded message from "Adams, Dean [EEOBS]" <dcad...@iastate.edu> -----

     Date: Wed, 3 Jul 2013 11:32:55 -0400
      From: "Adams, Dean [EEOBS]" <dcad...@iastate.edu>
      Reply-To: "Adams, Dean [EEOBS]" <dcad...@iastate.edu>
      Subject: RE: tps format problem reading in R
      To: "morphmet@morphometrics.org" <morphmet@morphometrics.org>

Hi John,

There were two issues here, and both of which have easy fixes. First, there is 
only 1 specimen in your tps file, and the current version of readland.tps() was 
written for datasets with more than one specimen (we didn't envision folks 
reading in a single specimen for a morphometric analysis).  This is easily 
fixed by changing the 3rd to last line of the function as below. Next, your 
file had a non-numeric ID for the specimen. To catch this, change the 4th to 
last line of the function as below.  These two lines should now read:

ID <-sub("ID=", "", tpsfile[grep("ID", tpsfile)])   #delete the 'as.numeric'
dimnames(coords)[[3]] <- as.list(imageID)   # add 'as.list'

The updated function code is attached, and will be in the next update of 
geomorph. 

Thanks for catching these; this makes the function more general. 

Best,

Dean

--
Dr. Dean C. Adams
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

-----Original Message-----
From: morphmet_modera...@morphometrics.org 
[mailto:morphmet_modera...@morphometrics.org] 
Sent: Wednesday, July 03, 2013 1:31 AM
To: morphmet@morphometrics.org
Subject: tps format problem reading in R

----- Forwarded message from John Denton <jden...@amnh.org> -----

Date: Tue, 2 Jul 2013 23:04:22 -0400
From: John Denton <jden...@amnh.org>
Reply-To: John Denton <jden...@amnh.org>
Subject: tps format problem reading in R
To: "morphmet@morphometrics.org" <morphmet@morphometrics.org>

Hi folks,

I'm trying to read a tps file in the geomorph v1.1-1 R package using

readland.tps("file"),

but every time I try the above, I get the error

Error in dimnames(coords)[[3]] <- imageID : 'dimnames' must be a list In 
addition: Warning message:
In readland.tps("Lter_mean.TPS") : NAs introduced by coercion 

I do not get the error when I read in some of my other tps files (all of which 
were produced using append files in tpsUtil). The file I'm trying to read in is 
the side-averaged Procrustes coordinates, generated in MorphoJ. 

I've checked the hidden formatting, the line breaks, the number of decimal 
places, and the file extension, but I can't seem to figure it out. 

The file is attached. 

~John

John S. S. Denton
Ph.D. Candidate
Department of Ichthyology and Richard Gilder Graduate School American Museum of 
Natural History www.johnssdenton.com

----- End forwarded message -----

----- End forwarded message -----

### Generalize readland.tps for files with a single specimen and non-numeric ID
        #DC Adams 3 July 2013

readland.tps<-function (file) 
{
  tpsfile <- scan(file = file, what = "char", sep = "\n", quiet = TRUE)
  lmdata <- grep("LM", tpsfile)
  n <- nspecs <- length(lmdata)
  land.dim <- length(grep("LM=", tpsfile[lmdata[1]]))
  if (land.dim != 0) {
    nland <- as.numeric(sub("LM=", "", tpsfile[lmdata]))
  }
  if (land.dim == 0) {
    nland <- as.numeric(sub("LM3=", "", tpsfile[lmdata]))
  }
  if (max(nland) - min(nland) != 0) {
    stop("Number of landmarks not the same for all specimens.")
  }
  p <- nland[1]
  k <- ifelse(land.dim != 0, 2, 3)
  imscale <- as.numeric(sub("SCALE=", "", tpsfile[grep("SCALE", 
                                                       tpsfile)]))
  if (is.null(imscale)) {
    imscale = array(1, nspecs)
  }
  if (length(imscale) != nspecs) {
    print("Not all specimens have scale. Using scale = 1.0")
  }
  if (length(imscale) != nspecs) {
    imscale = array(1, nspecs)
  }
  landdata <- matrix(NA, nrow = (p * n), ncol = k)
  for (i in 1:n) {
    for (j in 1:p) {
      tmp <- gsub("\\t", " ", tpsfile[lmdata[i] + j])
      tmp <- as.numeric(unlist(strsplit(tmp, split = " +"))) * 
        imscale[i]
      landdata[((i - 1) * p) + j, ] <- tmp
      rownames(landdata) <- NULL
    }
  }
  coords <- arrayspecs(landdata, p, k)
  imageID <- (sub("IMAGE=", "", tpsfile[grep("IMAGE", tpsfile)]))
  imageID <- sub(".jpg", "", imageID)
  imageID <- sub(".tif", "", imageID)
  imageID <- sub(".bmp", "", imageID)
  imageID <- sub(".tiff", "", imageID)
  imageID <- sub(".jpeg", "", imageID)
  imageID <- sub(".jpe", "", imageID)
  ID <-sub("ID=", "", tpsfile[grep("ID", tpsfile)])  #changed, so ID can be 
non-numeric: 2 July , 2013
  dimnames(coords)[[3]] <- as.list(imageID)          #changed to read file with 
only 1 specimen: 2 July, 2013
  return(coords = coords)
}

Reply via email to