AtlasOfLivingAustralia / galah-R

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

`dataResourceName`'s with ampersands (`"&"`) in their string cause a parsing error #203

Closed cjwaite23 closed 11 months ago

cjwaite23 commented 1 year ago

Describe the bug Parsing error when using atlas_counts() or atlas_occurrences() with piping from galah_filter() or galah_group_by() for the dataResourceName field when resources involve ampersands.

galah version 1.5.3 (but also present in 1.5.1-1.5.2)

To Reproduce We note that there are a handful of values in the dataResourceName field that include ampersands (&). These can be found by

> search_fields("dataResourceName") |> show_values() |> filter(str_detect(category, "&"))
! Search returned 2 matched fields.
• Showing values for 'dataResourceName'.
# A tibble: 5 × 2
  field            category                                       
  <chr>            <chr>                                          
1 dataResourceName Port Adelaide Enfield Flora & Fauna Monitoring 
2 dataResourceName NSW South Coast & ACT plants                   
3 dataResourceName Manning & Great Lakes - NSW Waterwatch         
4 dataResourceName Pinao'ula: Dragonflies & damselflies of Hawai'i
5 dataResourceName Wetlands & Wildlife Creations Group

When trying to filter or group_by these records, a parsing error occurs which does not present itself for any other data records.

> galah_call() |>
+     galah_filter(dataResourceName == "SA Fauna") |>
+     atlas_counts()
# A tibble: 1 × 1
    count
    <int>
1 1727992
> galah_call() |>
+     galah_filter(dataResourceName == "NSW South Coast & ACT plants") |>
+     atlas_counts()
Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:1: unexpected INCOMPLETE_STRING
1: "NSW South Coast
    ^
> galah_call() |>
+     galah_filter(dataResourceName == "Pinao'ula: Dragonflies & damselflies of Hawai'i") |>
+     atlas_counts()
Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:1: unexpected INCOMPLETE_STRING
1: "Pinao'ula: Dragonflies
    ^

This behaviour also presents itself when using galah_group_by():

> galah_call() |>
+     galah_filter(genus == "Platycercus", year == 2023) |>
+     galah_group_by(scientificName, dataResourceName) |>
+     atlas_counts()
Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:1: unexpected INCOMPLETE_STRING
1: 'Port Adelaide Enfield Flora
    ^

Expected behaviour We would expect the functions to behave as shown above when filtering for dataResourceName == "SA Fauna"

We suspect this may be due to how the queries are being translated.

daxkellie commented 1 year ago

Thanks for flagging this issue. Just tested these queries in the dev version for galah 2.0 and they run correctly, so this issue should be fixed in the next release 😃