AtlasOfLivingAustralia / galah-R

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

`atlas_counts()` hits error depending on order of fields in `galah_group_by()` or presence of `galah_identify()` #201

Closed daxkellie closed 8 months ago

daxkellie commented 12 months ago

In galah 1.5.3, when attempting to use galah_group_by() and atlas_counts() to return counts grouped by multiple fields, a strange error can be returned occasionally, stating that the by argument has not been set correctly

library(galah)

# does not work
galah_call() |>
  identify("Ericaceae") |>
  filter(year > 2022) |>
  group_by(el674, kingdom) |>
  count()
#> Error: 'by' must be one of: limit_offset, page_perpage

However, this error does not occur if the order of fields in group_by() are swapped

# works
galah_call() |>
  identify("Ericaceae") |>
  filter(year > 2022) |>
  group_by(kingdom, el674) |>
  count()
#> # A tibble: 1 × 3
#>   el674 kingdom count
#>   <chr> <chr>   <int>
#> 1 99.0  Plantae    75

or if galah_identify() is not present in the query

# works
galah_call() |>
  filter(year > 2022) |>
  group_by(el674, kingdom) |>
  count()
#> # A tibble: 5,099 × 3
#>    kingdom  el674 count
#>    <chr>    <chr> <int>
#>  1 Animalia 4.0   58477
#>  2 Animalia 3.0   43663
#>  3 Animalia 0.0   40120
#>  4 Animalia 8.0   38736
#>  5 Animalia 7.0   35530
#>  6 Animalia 1.0   35147
#>  7 Animalia 6.0   34959
#>  8 Animalia 10.0  32382
#>  9 Animalia 17.0  31689
#> 10 Animalia 2.0   29914
#> # ℹ 5,089 more rows

Created on 2023-07-11 with reprex v2.0.2

My guess is that this could be the result of a small parsing error in an internal grouping function within galah_group_by() or atlas_counts()?