subset neuronlist doesn't work with functions
dokato opened this issue · comments
For a neuronlist of neurons when I call:
> trimmed_partners <- subset(n_partners, function(x) {
+ sq_diffs <- t(t(x) - mid_point)^2
+ sqrt(rowSums(sq_diffs)) < radius
+ })
getting
Error in subset.neuronlist(n_partners, function(x) { :
Use of subset with functions is deprecated. Please use filterfun argument
Following the suggesting, I tried with filterfun
:
trimmed_partners <- subset(n_partners, filterfun = function(x) {
+ sq_diffs <- t(t(x) - mid_point)^2
+ sqrt(rowSums(sq_diffs)) < radius
+ })
Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
'data' must be of a vector type, was 'NULL'
[..]
Warning message:
In subset.neuronlist(n_partners, filterfun = function(x) { :
filterfun failed to evaluate for 7 entries in neuronlist
but this fails too. I can make it work with nlapply, but I thought that subset with filterfun
should work in that case.
Thanks @dokato. Could you provide a full reprex?
Sure, see below:
library(nat)
mid_point = colMeans(xyzmatrix(Cell07PNs[[1]]))
trimmed_partners <- subset(Cell07PNs[2:11], filterfun = function(x) {
sq_diffs <- t(t(x) - mid_point)^2
sqrt(rowSums(sq_diffs)) < 100
})
Actually, while writing that I realised that the subset.neuronlist
and subset.neuron
serve very different purpose. I wanted to extrapolate points selection from a single neuron and extend it to a collection, whereas subset.neuronlist
let's you select specific neruons from a list, given the condition (which might be specified by function).
Well, in that case using nlapply
sounds logical...