Skip to content

Some database values look like an numeric, but get_acoustic_detections() doesn't support numeric values in arguments. #407

@PietrH

Description

@PietrH
  • The old version of etn (2.2.2.9000) also doesn't support numeric arguments
  • The old verison of etn (2.2.2.9000) also doesn't have a nice error message

If you want to query some detections, and you want to filter by a value that happens to look by a numeric, you might be tempted to pass it as a numeric to the function.

For example:

get_acoustic_detections(tag_serial_number = 1400185)

Currently this results in a cryptic openCPU error:

etn::get_acoustic_detections(tag_serial_number = 1400185)
#> ℹ Preparing
#> Error in `get_acoustic_detections_page()`:
#> ! ODBC failed with error 00000 from \
#>              .
#> 
#> In call:
#> opencpu:::rapachehandler()
#> 
#> Backtrace:
#>     ▆
#>  1. └─watcher$push(cnd)
#>  2.   └─handler$error(value)
#> 
#> ℹ This is an error forwarded via the API.
#> ✖ Preparing  [2.9s]
#> 

Created on 2025-10-01 with reprex v2.1.1

Either, we should support this by casting all values passed to the database (regardless of protocol) as character, or I should improve the error messaging for this situation in etnservice

Example values:

I've written some code to find some examples of values that could be cast into numeric:

# Find values from list functions that have a value that can be cast into numeric
library(etn)
ls("package:etn", pattern = "^list_") |>
  purrr::set_names() |>
  # Remove list_values() helper, it doesn't list database values. It's used for
  # listing unique values in a column of a data.frame, nothing to do with what
  # I'm doing here.
  purrr::discard(~ .x == "list_values") |>
  purrr::map(~ do.call(.x, args = list())) |>
  purrr::map(\(values) {
    purrr::keep(values, \(x) !is.na(suppressWarnings(as.numeric(x))))
  }) |>
  # Don't list arguments that do not have values that look like numerics
  purrr::keep(~length(.x) > 0) |>
  # Only keep 10 examples
  purrr::map(\(values) sample(values, size = 10))
#> $list_animal_ids
#>  [1]  63730  73830  69642  97186 118282 114731   6095   8111 118434  59784
#> 
#> $list_deployment_ids
#>  [1] "67105" "72089" "59813" "64000" "68322" "12972" "66710" "64443" "4369" 
#> [10] "29354"
#> 
#> $list_station_names
#>  [1] "19"     "481209" "76"     "27"     "5.2"    "116"    "156"    "63"    
#>  [9] "551083" "131819"
#> 
#> $list_tag_serial_numbers
#>  [1] "1321798" "1255010" "1358017" "1336117" "1198464" "1353457" "1598523"
#>  [8] "1184628" "3215"    "1333385"

Created on 2025-10-01 with reprex v2.1.1


Related to #290

  • datapackage.json is the best place to keep field metadata.
  • tag_serial_number is specified as an Integer there. Why doesn't it work if we pass it as an integer?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions