Skip to content

consider adding a nid() function to handle numeric ids #505

@jefferis

Description

@jefferis

ids are identifiers not indices. Something like this might be possible:

nid <- function(...) {
  sc <- sys.call()
  scc=as.character(sc)
  stopifnot(scc[1]=='nid')
  i64=bit64::as.integer64(scc[-1])
  max64=bit64::as.integer64("9223372036854775807")
  if(isTRUE(any(i64<0, na.rm = T)) || 
     isTRUE(any(i64==max64, na.rm = T))) {
    badids=!fafbseg::valid_id(i64)
    if(any(badids)) {
      warning("there are bad ids:", paste(scc[-1][badids], collapse = ','))
      i64[badids]=NA
    }
  }
  class(i64)=union("nid", class(i64))
  i64
}

It doesn't look like there is a conflicting nid definition in packages that natverse users typically have. This might even belong in nat.utils. Would also need to figure out how to handle arguments that contain numeric ids rather than actually being one. This could be part of the solution to the common problem of indexing a neuronlist with numeric ids.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions