Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make colspace() work when columns are not in expected order #192

Open
Bisaloo opened this issue Feb 18, 2020 · 1 comment
Open

Make colspace() work when columns are not in expected order #192

Bisaloo opened this issue Feb 18, 2020 · 1 comment

Comments

@Bisaloo
Copy link
Collaborator

Bisaloo commented Feb 18, 2020

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)

di <- sensmodel(c(440, 330))
names(di) <- c("wl", "l", "s")

di_vis <- as.data.frame(vismodel(flowers, visual = di))

head(di_vis)
#>                               l            s lum
#> Goodenia_heterophylla 0.9730821 0.0269178704  NA
#> Goodenia_geniculata   0.9507922 0.0492078038  NA
#> Goodenia_gracilis     0.9247331 0.0752668919  NA
#> Xyris_operculata      0.9997937 0.0002062707  NA
#> Eucalyptus_sp         0.9796303 0.0203697463  NA
#> Faradaya_splendida    0.8829416 0.1170583601  NA

head(colspace(di_vis))
#> Warning: Input data is not a "vismodel" object *and* has more than two columns;
#> treating the first two columns as standardized quantum catch for "s", and "l"
#> receptors, respectively
#>                               s            l          x     r.vec lum
#> Goodenia_heterophylla 0.9730821 0.0269178704 -0.6690392 0.6690392  NA
#> Goodenia_geniculata   0.9507922 0.0492078038 -0.6375164 0.6375164  NA
#> Goodenia_gracilis     0.9247331 0.0752668919 -0.6006633 0.6006633  NA
#> Xyris_operculata      0.9997937 0.0002062707 -0.7068151 0.7068151  NA
#> Eucalyptus_sp         0.9796303 0.0203697463 -0.6782996 0.6782996  NA
#> Faradaya_splendida    0.8829416 0.1170583601 -0.5415613 0.5415613  NA

Created on 2020-02-18 by the reprex package (v0.3.0)

In the colspace object, the s and l columns are swapped. This is consistent with the warning but it would be nice if pavo could work with this out of the box.

@thomased
Copy link
Collaborator

Yeah I started to chip away at this as part of a more general attempt at #102, but got tangled up. I suspect it'd be simplest to first refactor out all those data-checks that are duplicated across the colspace functions (hexagon, trispace etc.), then just fix it in the one spot. That change is simple enough — we just need to be smarter about checking the structure of the data — but might take a little effort to get there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants