Skip to content

Commit

Permalink
check that neuron writer accepts metadata
Browse files Browse the repository at this point in the history
* otherwise lots of errors
  • Loading branch information
jefferis committed Jul 12, 2021
1 parent f8148fe commit bcdbfd2
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions R/neuron-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit bcdbfd2

Please sign in to comment.