After updating to most recent version - ERROR: duplicate 'row.names' are not allowed

905 views
Skip to first unread message

Bob LePaul

unread,
Dec 11, 2021, 5:25:45 PM12/11/21
to geomorph R package
Good morning everybody,

after updating my R to the most recent version (4.1.2), including the most recent geomorph (4.0.1) and RRPP package, I find myself unable to re-run code that worked just fine before (R 4.1.0, geomorph 4.0.0). While importing data, procrustes analysis and creating a geomorph.data.frame works just fine, I cannot run my models (procD.lm or lm.rrpp) anymore. That is because R returns this error: "ERROR: duplicate 'row.names' are not allowed" and I cannot figure out why. Looking at the structure of the geomorph.data.frame, I cannot find anything unusual either.

Here is my code:

Data <- readland.tps("measurements.tps",
  specID = c("ID"),
  negNA = FALSE,
  warnmsg = TRUE,
  readcurves = TRUE
)

define.sliders(Data[,,1], nsliders=18, surfsliders = FALSE, write.file=T)

datcurves <- as.matrix(read.csv("curveslide.csv", header=T))

shape <- gpagen(Data, curves=datcurves)$coords
csize <- gpagen(Data, curves=datcurves)$Csize
extra <- read.table("extra-data.txt", header=TRUE, stringsAsFactors=TRUE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE)

dat.full <- geomorph.data.frame(coords=shape, csize=csize, family=extra$cage)

str(dat.full)

List of 3
 $ coords : num [1:29, 1:2, 1:127] 0.270 0.224 0.220 0.191 0.132 ...
  ..- attr(*, "dimnames")=List of 3
  .. ..$ : chr [1:29] "1" "2" "3" "4" ...
  .. ..$ : chr [1:2] "X" "Y"
  .. ..$ : chr [1:127] "0 " "1 " "2 " "3 " ...
 $ csize  : Named num [1:127] 14.7 11.3 13.6 13.5 13 ...
  ..- attr(*, "names")= chr [1:127] "0 " "1 " "2 " "3 " ...
 $ family : Factor w/ 11 levels "A1","B1",..: 9 9 10 11 1 4 11 4 10 10 ...
 - attr(*, "class")= chr "geomorph.data.frame"

m.1<-procD.lm(coords~csize+family, iter=999, data=dat.full, RRPP=TRUE, SS.type="II", print.progress=FALSE)

ERROR: duplicate 'row.names' are not allowed

Might anyone here see what is wrong? The code ran just fine in the older R version.

Thank you for your help!
Bob

Bob LePaul

unread,
Dec 11, 2021, 5:47:18 PM12/11/21
to geomorph R package
A quick fix is to apply unname() to all variables, e.g.

dat.full$coords <- unname(dat.full$coords)
dat.full$csize <- unname(dat.full$csize)
dat.full$family <- unname(dat.full$family)

However, I would like to resolve the underlying issue as it might be an incompatibility issue between geomorph and the current R version.

Bryan H. Juarez

unread,
Dec 11, 2021, 5:52:59 PM12/11/21
to geomorph-...@googlegroups.com
Hi Bob, 

I'd be careful with unname(), since you would presumably want to combine rows in some way if they do in fact share some quality like a name, group assignment, species, etc.

The error is telling you that the objects (rows) you are comparing have a name that appears twice in your dataset.
Have you tried checking dimnames(coords)? 

Here is an example using the Pupfish dataset that might help:
data("PupfishHeads")
#manually duplicate a rowname: change dimname 2 to be same as dimname 1
dimnames(PupfishHeads$coords)[[1]][2] <- dimnames(PupfishHeads$coords)[[1]][1] 
fit <- lm.rrpp(coords ~ sex, data = PupfishHeads)
Error in `.rowNamesDF<-`(x, value = value) :
  duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique value when setting 'row.names': ‘395’ 


The example shows the same error as yours and the warning tells me the name that is duplicated is "395". Removing the line where I manually duplicate a rowname resolves the issue.

Hope that helps,
Bryan


--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/99f9ecf5-69c1-4dba-8c9e-6b924d01b254n%40googlegroups.com.


--
Bryan H. Juarez, PhD 
He/Him
NSF Postdoctoral Scholar
O'Connell and Hadly Labs
Biology Dept.
Stanford University
Twitter: @bhjuarez


Bob LePaul

unread,
Dec 11, 2021, 6:02:35 PM12/11/21
to geomorph R package
Thank you. By using dimnames(), I found that one ID number in the original tps file was indeed duplicated. I resolved this issue by changing it and the model runs fine now. Thank you. I am just surprised this error did not appear in earlier R versions.

Miriam Zelditch

unread,
Dec 11, 2021, 6:36:55 PM12/11/21
to geomorph R package
This error is a new R thing. You can deal with it by the function make.unique
Like in this example
test<-make.unique(rownames(myFile), sep = ".")# This adds a number separated by the separator to the second instance of the name
rownames(myFile)<-test

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.


--
Miriam Zelditch
Associate Research Scientist
Museum of Paleontology
University of Michigan
Ann Arbor, MI  48109-1079
Reply all
Reply to author
Forward
0 new messages