Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jefferis opened this issue Aug 25, 2022 · 0 comments
Open

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

jefferis opened this issue Aug 25, 2022 · 0 comments
Labels

Comments

@jefferis
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant