-
Notifications
You must be signed in to change notification settings - Fork 28
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
WIP: added withMeta parameter to nlapply #501
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,6 +388,8 @@ as.data.frame.neuronlist<-function(x, row.names = names(x), optional = FALSE, .. | |
#' error. The default value (\code{NA}) will result in nlapply stopping with | ||
#' an error message the moment there is an error. For other values, see | ||
#' details. | ||
#' @param withMeta whether or not to include the metadata from the neuronlist | ||
#' data.frame | ||
#' @param .progress Character vector specifying the type of progress bar (see | ||
#' Progress bar section for details) The default value of \code{"auto"} shows | ||
#' a progress bar in interactive use after 2s. The default value can be | ||
|
@@ -479,7 +481,7 @@ as.data.frame.neuronlist<-function(x, row.names = names(x), optional = FALSE, .. | |
#' options(nat.progress=NULL) | ||
#' sl=nlapply(Cell07PNs, FUN = seglengths) | ||
#' } | ||
nlapply<-function (X, FUN, ..., subset=NULL, OmitFailures=NA, | ||
nlapply<-function (X, FUN, ..., subset=NULL, OmitFailures=NA, withMeta=FALSE, | ||
.progress=getOption('nat.progress', default='auto')){ | ||
if(isTRUE(.progress=='auto')) { | ||
.progress = ifelse(interactive(), "natprogress", "none") | ||
|
@@ -495,6 +497,12 @@ nlapply<-function (X, FUN, ..., subset=NULL, OmitFailures=NA, | |
class(X) | ||
else c("neuronlist", 'list') | ||
|
||
if (withMeta && ncol(X[,]) > 0) { | ||
meta_list <- split(X[,], seq(nrow(X[,]))) | ||
Xlist = mapply(append, X, meta_list, SIMPLIFY = FALSE) | ||
X = as.neuronlist(lapply(Xlist, as.neuron)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work if X contains dotprops rather than neuron objects. I think you need to set the class based on the class of each element of X before appending. I guess you have to use |
||
} | ||
|
||
if(!is.null(subset)){ | ||
if(!is.character(subset)) subset=names(X)[subset] | ||
Y=X | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,6 +327,24 @@ test_that("[<-.neuronlist does the right thing",{ | |
expect_null(colnames(kcs13[,]<-NULL)) | ||
}) | ||
|
||
test_that("neuronlist includes metadata",{ | ||
kcs13=kcs20[1:3] | ||
|
||
# expect that withMeta output will contain more attributes | ||
out1 = nlapply(kcs13, function(x) x) | ||
out2 = nlapply(kcs13, function(x) x, withMeta = T) | ||
expect_true( | ||
length(attributes(out1[[2]])$names) < length(attributes(out2[[2]])$names) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this was the intention:
|
||
|
||
# or parts of columns | ||
data.frame(kcs13) <- NULL | ||
out3 = nlapply(kcs13, function(x) x, withMeta = T) | ||
expect_true( | ||
all(names(out1[[1]]) == names(out3[[1]])) | ||
) | ||
}) | ||
|
||
test_that("prune twigs of a neuronlist", { | ||
n = Cell07PNs[1:3] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is 100% clear yet. I think you need to add something like "in the body of each object in the output list"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intention that the metadata dataframe should be removed from the output? It is. Maybe this should be signalled.