FRBCesab / funbiogeo

:package: R package to help with analyses in functional biogeography
https://frbcesab.github.io/funbiogeo/
GNU General Public License v2.0
10 stars 1 forks source link

All NA values for some traits make site-trait completeness plot errors #110

Closed Rekyt closed 5 months ago

Rekyt commented 5 months ago

Bug description

When some traits are all NAs the site-trait completeness plot bugs

Reproducible example

library("funbiogeo")

ko = species_traits

# Good color
fb_plot_site_traits_completeness(site_species, ko)


# NA is of good color
ko$litter_size = NA
fb_plot_site_traits_completeness(site_species, ko)
#> Error: No species found in common between inputs

# NaN is not (only in the column)
ko$litter_size = NaN
fb_plot_site_traits_completeness(site_species, ko)
#> Error: No species found in common between inputs

# Inf is indeed detected as a complete value
ko$litter_size = Inf
fb_plot_site_traits_completeness(site_species, ko)

Created on 2024-04-07 with reprex v2.1.0

Rekyt commented 5 months ago

This bug is caused by the following line: https://github.com/FRBCesab/funbiogeo/blob/497d97a96b24dce6cec6325095d46e96f4876211/R/fb_get_trait_coverage_by_site.R#L44

Which normally assumes that we only get a row for species which have all known traits. Species with NA traits are silently dropped and not considered when computing coverage.

We should remedy this issue by thinking about how species with NA traits should be considered from the point of view of coverages.