From 8ee9d4a4b38b4ac90b5278c39fbee40ea1f022fd Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 30 Aug 2023 22:33:30 +0100 Subject: [PATCH] handle plain coordinates in neuprint_list2df * picked up because of a problem with malevnc dataset * with test and updated baseline --- R/fetch.R | 15 ++++++------ tests/testthat/test-fetch.R | 23 +++++++++++-------- tests/testthat/testdata/neuprint_list2df.rds | Bin 311 -> 337 bytes 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/R/fetch.R b/R/fetch.R index 4f13f5a1..e20d34f8 100644 --- a/R/fetch.R +++ b/R/fetch.R @@ -104,14 +104,13 @@ neuprint_list2df <- function(x, cols=NULL, return_empty_df=FALSE, raw_col=if(is.list(firstrec) && !is.null(firstrec$coordinates)) { # special case coordinates lapply(x, function(r) r[[colidx]][['coordinates']]) - } else sapply(x, "[[", colidx) - if(is.list(raw_col)) { - raw_col[sapply(raw_col, is.null)]=NA - sublens=sapply(raw_col, length) - if(all(sublens==1)) - raw_col=unlist(raw_col) - else raw_col=sapply(raw_col, paste, collapse=',') - } + } else lapply(x, "[[", colidx) + sublens=lengths(raw_col) + if(all(sublens%in% 0:1)) { + if(any(sublens==0)) + raw_col[sublens==0]=NA + raw_col=unlist(raw_col) + } else raw_col=sapply(raw_col, paste, collapse=',') l[[cols[i]]]=raw_col } as.data.frame(l, stringsAsFactors=stringsAsFactors, check.names=check.names, ...) diff --git a/tests/testthat/test-fetch.R b/tests/testthat/test-fetch.R index 28df8ca7..095671ae 100644 --- a/tests/testthat/test-fetch.R +++ b/tests/testthat/test-fetch.R @@ -6,18 +6,20 @@ test_that("neuprint_list2df works", { "USN_id", "USN_name", "USN_size", - "weight" + "weight", + "plain_coords" ), data = list( list(328253133L, "Rhubarb 1", - 1420595727L, NULL, 7788L, 1L), + 1420595727L, NULL, 7788L, 1L, as.list(1:3)), list( 5813098776, "Rhubarb 2", 1327197051L, NULL, 18585L, - 1L + 1L, + as.list(1:3) ), list( 737167616L, @@ -25,21 +27,23 @@ test_that("neuprint_list2df works", { 1327197051L, NULL, 18585L, - 1L + 1L, + as.list(1:3) ), list(923027316L, "Rhubarb 4", - 5901216241, NULL, 29022L, 1L), + 5901216241, NULL, 29022L, 1L, as.list(1:3)), list(675468771L, "Rhubarb 5", - 5901213372, NULL, 34868L, 1L), + 5901213372, NULL, 34868L, 1L, as.list(1:3)), list(1295855722L, "Rhubarb 6", - 1328285179L, NULL, 35121L, 1L), + 1328285179L, NULL, 35121L, 1L, as.list(1:3)), list( 644417074L, "Rhubarb 7", 1232478011L, NULL, 38389L, - 1L + 1L, + as.list(1:3) ), list( 1141337557L, @@ -47,7 +51,8 @@ test_that("neuprint_list2df works", { 1232478011L, NULL, 38389L, - 1L + 1L, + as.list(1:3) ) ) ) diff --git a/tests/testthat/testdata/neuprint_list2df.rds b/tests/testthat/testdata/neuprint_list2df.rds index cb690b8d807a45180072e29553a83e9ea52a4aa3..9441fb58ac8afb880c3a76104818ad7a64eb340f 100644 GIT binary patch delta 171 zcmV;c0960C0?`5^iMgr8&_HH`3NmG;Kv^sxX(*d5G}td5F2e!hA<2UI#hF!b)#a&~=@}*H)+Og8 y7Q?KA338<*mL%$>6@d&xRnA$IU#SAC#)0ssIClsppv