laminlabs / laminr

R client for LaminDB.
http://laminr.lamin.ai/
Apache License 2.0
8 stars 1 forks source link

`from_anndata`, `from_path`, ... only needs to be added to the Artifact Registry #87

Open rcannood opened 5 days ago

rcannood commented 5 days ago

Functions like from_path and from_anndata should only be added if the class is an Artifact Registry.

We probably need a

create_registry <- function(instance, module, api, registry_name, registry_schema) {
  public <- list(
    initialize = function(instance, module, api, registry_name, registry_schema) {
      super$new(
        instance = instance,
        module = module,
        api = api,
        registry_name = registry_name,
        registry_schema = registry_schema
      )
    },
    # ...
  )

  if (registry_name == "Artifact") {
    public$from_path <- ...
    public$from_anndata <- ..
    public$from_dir <- ...
    public$from_mudata <- ...
  }
  if (registry_names == "FeatureSet") {
    public$from_values <- ...
  }
  # ...

  RichRegistryClass <- R6::R6Class(
    paste0(registry_name, "Registry"),
    cloneable = FALSE,
    inherit = Registry,
    public = public
  )

  RichRegistryClass
}

Or the other way around

create_registry <- function(instance, module, api, registry_name, registry_schema) {
  public <- list(
    initialize = function(instance, module, api, registry_name, registry_schema) {
      super$new(
        instance = instance,
        module = module,
        api = api,
        registry_name = registry_name,
        registry_schema = registry_schema
      )
    },
    from_path = function(...) {
      ...
    },
    from_anndata = function(...) {
      ...
    },
    from_dir = function(...) {
      ...
    },
    # ...
  )

  if (registry_name != "Artifact") {
    public$from_path <- NULL
    public$from_anndata <- NULL
    public$from_dir <- NULL
    public$from_mudata <- NULL
  }
  if (registry_names != "FeatureSet") {
    public$from_values <- NULL
  }
  # ...

  RichRegistryClass <- R6::R6Class(
    paste0(registry_name, "Registry"),
    cloneable = FALSE,
    inherit = Registry,
    public = public
  )

  RichRegistryClass
}

_Originally posted by @rcannood in https://github.com/laminlabs/laminr/pull/85#discussion_r1848335300_

rcannood commented 5 days ago

Somewhat related to #63