rmaia / pavo

tools for the analysis of color data in R
http://pavo.colrverse.com
GNU General Public License v2.0
69 stars 17 forks source link

summary.colspace fails with obscure error when by != multiple of number of spectra #200

Closed Bisaloo closed 4 years ago

Bisaloo commented 4 years ago

Reprex:

library(pavo)
#> Welcome to pavo 2! Take a look at the latest features (and update your bibliography) in our recent publication: Maia R., Gruson H., Endler J. A., White T. E. (2019) pavo 2: new tools for the spectral and spatial analysis of colour in R. Methods in Ecology and Evolution, 10, 1097-1107.

data(flowers)

# Works
summary(colspace(vismodel(flowers)), by = 6)
#> Colorspace & visual model options:
#>  * Colorspace: tcs 
#>  * Quantal catch: Qi 
#>  * Visual system, chromatic: avg.uv 
#>  * Visual system, achromatic: none 
#>  * Illuminant: ideal, scale = 1 (von Kries colour correction not applied) 
#>  * Background: ideal 
#>  * Relative: TRUE 
#>  * Max possible chromatic volume: 0.215735
#>                        centroid.u centroid.s centroid.m centroid.l        c.vol
#> Goodenia_heterophylla  0.03391090  0.2386183  0.3313181  0.3961527 0.0006593772
#> Gaultheria_hispida     0.08548042  0.2889119  0.2533627  0.3722450 0.0027874727
#> Glycine_clandestina    0.05779144  0.2292408  0.3202973  0.3926705 0.0002769699
#> Gonocarpus_humilis     0.07982053  0.1582365  0.3605185  0.4014244 0.0005275599
#> Goodenia_rotundifolia  0.05182030  0.2657366  0.3242820  0.3581611 0.0010995427
#> Hardenbergia_violaceae 0.05271537  0.2446261  0.3180592  0.3845993 0.0010934146
#>                          rel.c.vol colspan.m   colspan.v huedisp.m huedisp.v
#> Goodenia_heterophylla  0.003045533 0.2006658 0.009325661 0.6780524 0.1042624
#> Gaultheria_hispida     0.012874785 0.2671142 0.019351647 1.0537225 0.2814636
#> Glycine_clandestina    0.001279269 0.1338162 0.004973007 0.4187161 0.0358544
#> Gonocarpus_humilis     0.002436695 0.1973938 0.008074460 0.7071089 0.1619304
#> Goodenia_rotundifolia  0.005078570 0.2606586 0.018179127 0.9602367 0.2583352
#> Hardenbergia_violaceae 0.005050266 0.1891680 0.009681716 0.7408079 0.1822846
#>                          mean.ra    max.ra
#> Goodenia_heterophylla  0.8643564 0.9991510
#> Gaultheria_hispida     0.7945259 0.9359717
#> Glycine_clandestina    0.7688342 0.9696703
#> Gonocarpus_humilis     0.8913997 0.9934568
#> Goodenia_rotundifolia  0.7927188 0.9839768
#> Hardenbergia_violaceae 0.8798700 0.9758965

# Fails
summary(colspace(vismodel(flowers)), by = 10)
#> Colorspace & visual model options:
#>  * Colorspace: tcs 
#>  * Quantal catch: Qi 
#>  * Visual system, chromatic: avg.uv 
#>  * Visual system, achromatic: none 
#>  * Illuminant: ideal, scale = 1 (von Kries colour correction not applied) 
#>  * Background: ideal 
#>  * Relative: TRUE 
#>  * Max possible chromatic volume: 0.215735
#> Error in factor(by, labels = row.names(object)[seq(1, length(row.names(object)), : invalid 'labels'; length 4 should be 1 or 3

Created on 2020-06-04 by the reprex package (v0.3.0)

I think it makes sense that it fails. It would just be better to add a more explicit error message.

thomased commented 4 years ago

6ff89ccaeeba6dbba953e1b57e9223a2d683233e ?

Bisaloo commented 4 years ago

Yes, thank you!

summary(colspace(vismodel(flowers)), by = 4)

still fails because of a different error in alphashape3d and I can't figure out what's wrong at the moment so I'll add a tryCatch()