AtlasOfLivingAustralia / galah-R

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

Feature request: Batch search record by catalogue number #91

Closed stiatragul closed 2 years ago

stiatragul commented 3 years ago

Hey Galah developers,

I think this is a great package with wonderful documentation. I think it would be helpful to for researchers to batch search records by catalogue number in the documentation. I tried something like this:

rego_to_search <- c(“R146400”, “R108813”, “R132006”)

ala_occurrences(filters = select_filters(
  catalogue_number %in% rego_to_search))

and got the error:

Error in if (filter_name %in% search_fields(type = "assertions")$id) { : 
  argument is of length zero

The manual way to do this in on Ozcam is through: https://ozcam.ala.org.au/search#tab_catalogUpload

Could you advise if batch search by catalogue number is available and how I can adjust my code to make it work?

mjwestgate commented 3 years ago

Thanks for getting in touch! It looks like there are three problems here, namely that select_filters:

  1. didn't parse rego_to_search, so doesn't know which catalogue numbers to look for
  2. doesn't recognise %in%
  3. doesn't recognise the field catalogue_name (you can use search_fields() to check this)

To solve this using galah v. 1.3.1 (i.e. current CRAN version), you could supply a vector directly, e.g.:

ala_counts(
  filters = select_filters(catalogNumber = c("R146400", "R108813", "R132006")), 
  group_by = "catalogNumber")

Alternatively, you could get the development version of galah and use the new syntax:

remotes::install_github("AtlasOfLivingAustralia/galah@dev")
library(galah)
rego_to_search <- c("R146400", "R108813", "R132006")
ala_counts(filters =  select_filters(catalogNumber = rego_to_search))

Note that this solves problems 1 & 3 above, but not 2. My instinct is that we shouldn't support using %in% in select_filters because it is typically used to compare two vectors in the home environment, rather than as syntax for a query. But I could be challenged on this.