natverse / nat

NeuroAnatomy Toolbox: An R package for the (3D) visualisation and analysis of biological image data, especially tracings of single neurons.
https://natverse.org/nat/
64 stars 29 forks source link

nlapply to include metadata from data.frame #500

Open dokato opened 2 years ago

dokato commented 2 years ago

Occasionally it happened to me that I needed to get some metadata information about the neuron that is kept in data.frame attribute. For example, I have a function that does action A if the neuron has soma, and action B if it doesn't. So far to achieve that I had to work around nlapply. I thought that including such metadata as attributes during iteration would be nice though. I.e.:

soma_radius <- function(n) {
  if (isTRUE(n$soma))
    n$d[n$d$Parent == -1,"W"]
  else 
   0
}