From bcdbfd2fb07077d56efadeac201087b43dbc7a7b Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Mon, 12 Jul 2021 21:32:38 +0100 Subject: [PATCH] check that neuron writer accepts metadata * otherwise lots of errors --- R/neuron-io.R | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/R/neuron-io.R b/R/neuron-io.R index 627d6b31..723379e4 100644 --- a/R/neuron-io.R +++ b/R/neuron-io.R @@ -733,19 +733,26 @@ write.neuron<-function(n, file=NULL, dir=NULL, format=NULL, ext=NULL, stop("Unable to write to file ",file) } + # OK all fine, so let's write + FUN=match.fun(fw$write) + + write_metadata=FALSE if(!is.null(metadata)) { - if(!is.character(metadata)){ - if(is.data.frame(metadata)) - metadata=as.list(metadata) - metadata=jsonlite::toJSON(metadata, auto_unbox = TRUE) + if(!isTRUE("metadata" %in% names(formals(FUN)))) + warning("neuron writing function does not accept metadata") + else { + write_metadata=TRUE + if(!is.character(metadata)){ + if(is.data.frame(metadata)) + metadata=as.list(metadata) + metadata=jsonlite::toJSON(metadata, auto_unbox = TRUE) + } + if(length(metadata)>1) + metadata=paste(metadata, collapse = ' ') } - if(length(metadata)>1) - metadata=paste(metadata, collapse = ' ') } - - # OK all fine, so let's write - FUN=match.fun(fw$write) - FUN(n, file=file, metadata=metadata, ...) + if(isTRUE(write_metadata)) FUN(n, file=file, metadata=metadata, ...) + else FUN(n, file=file, ...) invisible(file) }