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

Bug in trait completeness matrix with non-continuous traits #79

Closed Rekyt closed 1 year ago

Rekyt commented 1 year ago

See reprex:

library("funbiogeo")

trait_df = data.frame(
  species = letters[1:3],
  quanti_trait = 1:3,
  quanti_trait2 = 4:6,
  character_trait = LETTERS[1:3],
  factor_trait    = factor(LETTERS[1:3])
)

# Works
fb_plot_species_traits_completeness(trait_df[, 1:3])


# Doesn't work
fb_plot_species_traits_completeness(trait_df[,1:4])
#> Error in `pivot_longer_spec()`:
#> ! Can't combine `quanti_trait` <integer> and `character_trait` <character>.

#> Backtrace:
#>      ▆
#>   1. ├─funbiogeo::fb_plot_species_traits_completeness(trait_df[, 1:4])
#>   2. │ ├─tidyr::pivot_longer(...)
#>   3. │ └─tidyr:::pivot_longer.data.frame(...)
#>   4. │   └─tidyr::pivot_longer_spec(...)
#>   5. │     └─vctrs::vec_ptype_common(...)
#>   6. └─vctrs (local) `<fn>`()
#>   7.   └─vctrs::vec_default_ptype2(...)
#>   8.     ├─base::withRestarts(...)
#>   9.     │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>  10.     │   └─base (local) doWithOneRestart(return(expr), restart)
#>  11.     └─vctrs::stop_incompatible_type(...)
#>  12.       └─vctrs:::stop_incompatible(...)
#>  13.         └─vctrs:::stop_vctrs(...)
#>  14.           └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))
fb_plot_species_traits_completeness(trait_df[, c(1, 3:4)])
#> Error in `pivot_longer_spec()`:
#> ! Can't combine `quanti_trait2` <integer> and `character_trait` <character>.

#> Backtrace:
#>      ▆
#>   1. ├─funbiogeo::fb_plot_species_traits_completeness(...)
#>   2. │ ├─tidyr::pivot_longer(...)
#>   3. │ └─tidyr:::pivot_longer.data.frame(...)
#>   4. │   └─tidyr::pivot_longer_spec(...)
#>   5. │     └─vctrs::vec_ptype_common(...)
#>   6. └─vctrs (local) `<fn>`()
#>   7.   └─vctrs::vec_default_ptype2(...)
#>   8.     ├─base::withRestarts(...)
#>   9.     │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>  10.     │   └─base (local) doWithOneRestart(return(expr), restart)
#>  11.     └─vctrs::stop_incompatible_type(...)
#>  12.       └─vctrs:::stop_incompatible(...)
#>  13.         └─vctrs:::stop_vctrs(...)
#>  14.           └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))

Created on 2023-02-24 with reprex v2.0.2