nat icon indicating copy to clipboard operation
nat copied to clipboard

consider adding a `nid()` function to handle numeric ids

Open jefferis opened this issue 2 years ago • 0 comments

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.

jefferis avatar Aug 25 '22 16:08 jefferis