AtlasOfLivingAustralia / galah-R

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

Create clearer error when unexpected function is piped to `galah_call()` #175

Closed daxkellie closed 1 year ago

daxkellie commented 1 year ago

At the moment, piping unexpected functions into galah_call() provides confusing error messages

galah_call() |>
  search_taxa("alces alces") |>
  atlas_counts()
#> Warning in stri_replace_all_regex(string, pattern,
#> fix_replacement(replacement), : argument is not an atomic vector; coercing
#> No taxon matches were found for "listidentify = NULL, select = NULL, filter =
#> NULL, geolocate = NULL, data_profile = NULL, group_by = NULL, down_to = NULL" in
#> the selected atlas (Australia).
#> Error in `atlas_counts()`:
#> ! Argument `request` requires an object of type `data_request`.
#> ℹ You can create this object using `galah_call()`
#> ℹ Did you specify the incorrect argument?

#> Backtrace:
#>     ▆
#>  1. └─galah::atlas_counts(search_taxa(galah_call(), "alces alces"))
#>  2.   └─galah:::check_data_request(request)
#>  3.     └─rlang::abort(bullets, call = caller_env())

Created on 2022-12-16 with reprex v2.0.2

Clearer information should be provided to users that they have piped an unaccepted function and even suggest a possible fix