@@ -298,11 +298,13 @@ as.data.frame.neuronlist<-function(x, row.names = names(x), optional = FALSE, ..
298298 nn = names(x )
299299 matching_rows = intersect(nn , rownames(value ))
300300 if (length(matching_rows )!= length(nn ) && any(nn %in% value [,1 ])) {
301- matching_rows_fc = intersect(nn , value [,1 ])
301+ # need to turn them into string
302+ candids <- id2char(value [,1 ])
303+ matching_rows_fc = intersect(nn , candids )
302304 if (length(matching_rows )< length(matching_rows_fc )){
303305 warning(" Matching neurons by first column." )
304306 matching_rows = matching_rows_fc
305- rownames(value ) <- value [, 1 ]
307+ rownames(value ) <- candids
306308 }
307309 }
308310 if (length(matching_rows )){
@@ -1140,3 +1142,19 @@ prune_twigs.neuronlist <- function(x, twig_length, OmitFailures=NA, ...) {
11401142 if (missing(twig_length )) stop(" Missing twig_length argument" )
11411143 nlapply(x , prune_twigs , twig_length = twig_length , OmitFailures = OmitFailures , ... )
11421144}
1145+
1146+ # helper function to convert numeric ids to character
1147+ id2char <- function (x ) {
1148+ if (is.character(x )) return (x )
1149+ if (is.integer(x ) || inherits(x , " integer64" )) return (as.character(x ))
1150+ # if(is.integer(x)) return(as.character(x))
1151+ if (is.numeric(x )) {
1152+ # this is the tricky one
1153+ # unfortunately it is slower than bit64::as.integer64
1154+ return (format(x , scientific = F ))
1155+ }
1156+ warning(" unrecognised id class:" , paste(class(x ), collapse = ' ,' ))
1157+ # we don't want to turn logical values into character
1158+ if (is.logical(x )) return (x )
1159+ as.character(x )
1160+ }
0 commit comments