matildabrown / rWCVP

Generating Summaries, Reports and Plots from the World Checklist of Vascular Plants
https://matildabrown.github.io/rWCVP/
GNU General Public License v3.0
19 stars 0 forks source link

Using wcvp_checklist() or wcvp_occ_mat() at the species level: Error in `wcvp_checklist()`: ! No occurrences. Are the rank and spelling correct? #62

Open MLieke opened 8 months ago

MLieke commented 8 months ago

Dear Matilda

Apologies if this is not the right place to ask this question, or the way I ask this question is not as it should be, I'm quite new to this.

Thank you for this really nice package!

I have a question regarding its use. I'm not sure if it's a bug or I'm doing something wrong, but every time I try to use wcvp_checklist() itself or wcvp_occ_mat() (which I guess uses wcvp_checklist()) at the species level, I get the following error: Error in wcvp_checklist(): ! No occurrences. Are the rank and spelling correct?

I thought maybe I'm writing the species names in an incorrect way, but this does not seem to be it (e.g. they work for the function wcvp_distribution()).

# this works fine
wcvp_distribution(taxon = "Poa annua", taxon_rank = "species")

# this works fine
wcvp_occ_mat(taxon = "Poa", taxon_rank = "genus",
             area_codes = get_wgsrpd3_codes("Europe"),
             native = TRUE,
             extinct = FALSE,
             location_doubtful = FALSE)

# this gives the error
wcvp_occ_mat(taxon = "Poa annua", taxon_rank = "species",
             area_codes = get_wgsrpd3_codes("Europe"),
             native = TRUE,
             extinct = FALSE,
             location_doubtful = FALSE)

Error in wcvp_checklist(): ! No occurrences. Are the rank and spelling correct? Backtrace:

  1. rWCVP::wcvp_occ_mat(...)
  2. rWCVP::wcvp_checklist(...)

Do you have an idea what is going wrong here and how I could solve it?

Thank you very much in advance and have a great weekend! Lieke

WDragon101 commented 8 months ago

Yes. I also realised this issue in wcvp_checklist(), wcvp_summary(). Maybe all methods contain parameter taxon_rank = c("species", "genus", "family", "order", "higher") will fail when using "species".

Here is my solution: wcvp_names <- rWCVPdata::wcvp_names wcvp_names$species <- wcvp_names$taxon_name wcvp_checklist(taxon = "Elymus czimganicus", taxon_rank = "species", wcvp_names = wcvp_names)

I checked the code of wcvp_checklist() and i knew why!

When we run wcvp_checklist(taxon="Elymus czimganicus", taxon_name="species"), wcvp_checklist() actually find "Elymus czimganicus" in the "species" column of rWCVPdata::wcvp_names. Unfortunately, the "species" column of rWCVPdata::wcvp_names is not what we think, you can see below:

image

So we will never get species occurrences accroding to species rank!

matildabrown commented 8 months ago

Hi both,

Sorry for my delayed response here.

We originally designed those functions to be used at genus level or above (so the above code should ideally throw a different error), but it looks like the option for taxon_rank = "species" crept in when we were standardising arguments during pre-release (oops!). I think the best solution is for me to update the functions so that they work for individual species, as is the case for the distribution mapping. I'll get to this ASAP and let you know once the patch is ready.

In the meantime, perhaps the best thing to do is to run the wcvp_* functions at the genus level, then dplyr::filter on the specific epithet.