AtlasOfLivingAustralia / galah-R

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

Support excluding records using `galah_filter()` with multiple conditions #176

Closed shandiya closed 1 year ago

shandiya commented 1 year ago

It's currently possible to use galah_filter() to include rows when filtering on multiple conditions, but not possible to similarly exclude rows with multiple conditions.

# include records where stateProvince == Victoria AND year == 2021
galah_call() |> 
  galah_identify("lathamus") |> 
  galah_filter(stateProvince == "Victoria" & year == 2021) |> 
  galah_select(species, year, stateProvince) |> 
  atlas_occurrences()
This query will return 642 records
Checking queue
Current queue size: 1. 0 
Running query on selected atlas
  |==============================================================================================| 100%
Downloading
# A tibble: 642 × 3                                                                                                                                                                                
   species            year stateProvince
   <chr>             <dbl> <chr>        
 1 Lathamus discolor  2021 Victoria     
 2 Lathamus discolor  2021 Victoria     
 3 Lathamus discolor  2021 Victoria     
 4 Lathamus discolor  2021 Victoria     
 5 Lathamus discolor  2021 Victoria     
 6 Lathamus discolor  2021 Victoria     
 7 Lathamus discolor  2021 Victoria     
 8 Lathamus discolor  2021 Victoria     
 9 Lathamus discolor  2021 Victoria     
10 Lathamus discolor  2021 Victoria     
# … with 632 more rows
# ℹ Use `print(n = ...)` to see more rows 

# exclude records where stateProvince == Victoria AND year == 2021
galah_call() |> 
  galah_identify("lathamus") |> 
  galah_filter(!(stateProvince == "Victoria" & year == 2021)) |> 
  galah_select(species, year, stateProvince) |>  
  atlas_occurrences()
Error in `FUN()`:
! Problem while evaluating `galah_filter(...)`.
Caused by error in `parse()`:
! <text>:2:0: unexpected end of input
1: !(stateProvince
   ^
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/rlang_error>
Error in `FUN()`:
! Problem while evaluating `galah_filter(...)`.
Caused by error in `parse()`:
! <text>:2:0: unexpected end of input
1: !(stateProvince
   ^
---
Backtrace:
  1. galah::atlas_occurrences(...)
 23. galah::galah_filter(...)
 24. galah:::parse_filter(dots)
 25. galah:::parse_inputs(dots)
 26. base::lapply(...)
 27. galah (local) FUN(X[[i]], ...)
 29. rlang::parse_expr(formula_df$variable[a])
 30. rlang::parse_exprs(x)
 31. rlang:::chr_parse_exprs(x)
 32. rlang:::map(x, function(elt) as.list(parse(text = elt)))
 33. base::lapply(.x, .f, ...)
 34. rlang (local) FUN(X[[i]], ...)
 36. base::parse(text = elt)
Run `rlang::last_trace()` to see the full context.
mjwestgate commented 1 year ago

Closed as completed by @daxkellie