NEON-biodiversity / Ostats

O-statistics (community pairwise niche overlap statistics)
https://neon-biodiversity.github.io/Ostats/
Other
7 stars 2 forks source link

ostat2longform not working for two sites? #8

Closed yyue-r closed 4 years ago

yyue-r commented 4 years ago

Ostat2longform does not seem to work if I only have two sites (it works in code supplement). The error is in the line res <- cbind(site = rep(dimnames(o[[1]])[[1]], each=ntrait), trait = rep(dimnames(o[[1]])[[2]], times=nsite), res)

Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 2, 0

qdread commented 4 years ago

@yyue-r Again it would be really helpful if you could give me the code that you used that produced this error, so that I can be sure we are looking at the same thing! :-D

yyue-r commented 4 years ago

It is also in the vignette! I think it's line 177.

qdread commented 4 years ago

OK I found the problem! Basically it is just that the traits object that was used to create Ostats_example did not have a column name. So then when you use dimnames to try to get the trait name, it returns NULL and then the cbind gives an error. So what I would do to fix this is to make sure the matrix has a name. In the vignette on line 74, replace dat$log_weight with dat[,'log_weight'] and you will get the exact same result except that the matrix will have a column name which will fix the error!

I didn't commit this change so I will leave it to you to do that in the vignette. I'll close it for now but let me know if this does not work!