Skip to content

move api argument to a package wide option, replace by enum. Envion: source argument for switching to parquet as a datasource. #377

@PietrH

Description

@PietrH

Currently, all functions in v2.3-beta and upwards have an api argument that you can use to select the source of the data, either a local database connection (on Rstudio: api = FALSE) or the web api via OpenCPU (api = TRUE).

There is the future plan of supporting a third source, which will allow unauthenticated access to open data. This is the first reason to change this argument over before a large scale public release. This data will be published as a static parquet file that will be refreshed on a stable interval (hourly? daily?) via a dump.

We should switch this source selecting argument to an enum, either retaining the argument name api = c(NULL,"opencpu"), or switching to something else like source = c("local","opencpu","parquet")

consider switching it to a option wide option, setting the api argument is contextually distant from the other arguments in most functions. And you'd generally only switch it on a per session basis, not on a by function basis: if you have access to a local database connection, that connection would be preferred.


Update 20250822

Had a discussion with Peter.

There is two variables:

  • source: where does the data come from, currently only the etn database, in the future, parquet open data, ...
  • protocol: how did I get it : either a local database connection, or via the opencpu api

Protocol

protocol: currently to use the opencpu api or not, most users don't need to bother with this. So the package can detect if the local database is available .onLoad and decide that way for all functions going forward. If a poweruser wants to change this anyway, they can change a system environemental variable to force it: ETN_PROTOCOL

.onLoad <- function(libname, pkgname) {
  # Package options
  op <- options()
  op.etn <- list(
    etn.protocol = "opencpu",
    etn.opencpu_url = "https://opencpu.lifewatch.be/library/etnservice/R"
  )
  toset <- !(names(op.etn) %in% names(op))
  if (any(toset)) options(op.etn[toset])

There is also the options package: https://dgkf.github.io/options/

Source

source is different in that it's closer to users, and will have different options for different functions. The first will be detections: get_acoustic_detections(protocol = c("parquet", "database")) to switch between parquet (or opendata) and the database to get detections from. The first option should always be the one where the users needs the least permissions for.

If there is ever an open rest api, this would become a source, since it'll return different things than opencpu. If opencpu is ever replaced by a different api that connects to the database directly, that would be a different protocol.

Metadata

Metadata

Assignees

Labels

APIactionableCan be implementeddocumentationImprovements or additions to documentation

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions