AtlasOfLivingAustralia / galah-R

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

Incorrect parsing of apostrophes (`'`) when using `%in%` #214

Closed daxkellie closed 4 months ago

daxkellie commented 7 months ago

Found by @fontikar, galah_filter() doesn't correctly parse apostrophes when using %in%

library(galah)

names <- c("Australia's Virtual Herbarium", 
           "iNaturalist observations",
           "iNaturalist research-grade observations")

# doesn't work
galah_call() |>
  filter(datasetName %in% names) |>
  atlas_counts()
#> Error in parse(text = x, keep.source = FALSE): <text>:1:27: unexpected symbol
#> 1: datasetName == 'Australia's
#>                               ^

# works
galah_call() |>
  galah_filter(datasetName == "Australia's Virtual Herbarium") |>
  atlas_counts()
#> # A tibble: 1 × 1
#>    count
#>    <int>
#> 1 269620

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

The current solution is to use escaping with \\

names <- c("Australia\\'s Virtual Herbarium",  # fixed
           "iNaturalist observations",
           "iNaturalist research-grade observations")

# works
galah_call() |>
  filter(datasetName %in% names) |>
  atlas_counts()
#> # A tibble: 1 × 1
#>     count
#>     <int>
#> 1 6025188

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

daxkellie commented 4 months ago

Fixed as of v2.0.1, test added in commit https://github.com/AtlasOfLivingAustralia/galah-R/commit/0e8428f23ecfdb021eef3011212032553c60078b