AtlasOfLivingAustralia / galah-R

Query living atlases from R
https://galah.ala.org.au
38 stars 3 forks source link

atlas_species() function fails against LA instance with la-pipelines generated index #234

Closed shahmanash closed 2 months ago

shahmanash commented 3 months ago

Describe the bug galah atlas_species() function fails against LA instance with la-pipelines generated index (Sweden, France, Spain)

galah version 2.0.1

To Reproduce Steps to reproduce the behaviour:

library(galah)
galah_config(email = "manash.shah@nrm.se", atlas = "Sweden")
galah_call() |>
  galah_identify("Corvus", "Taraxacum")|>
  atlas_species()|> 
  gt::gt()

See error

Error in `check_fields()`:
! Can't use fields that don't exist.
ℹ Use `search_all(fields)` to find a valid field ID.
✖ Can't find field(s) in
  • `galah_group_by()`: species_guid

Fix The species_facets function defined in R/utilities_internal.R needs to be updated as below

species_facets <- function(){
  atlas <- pour("atlas", "region")
  switch(atlas,
         "Australia" = "speciesID",
         # "Austria" = "species_guid",
         # "Brazil" = "species_guid",
         # "Canada" = "species_guid"
         "Sweden" = "speciesID",
         "France" = "speciesID",
         "Spain" = "speciesID",
         "species_guid"
  )
}

Better Fix In a number of function, fields or a list of fields are being specified on a per LA instance basis. Instead of adding the field for individual atlas instances, maybe a column could be added to thedata-raw/node_config.csv file to indicate if the instance is using la-pipelines generated index or the legacy biocache-cli tool . This field could also be used in a similar situation in default_columns function in R/galah_select.R