Skip to content

Commit

Permalink
Merge pull request #172 from natverse/fix/list2df-plain-coords
Browse files Browse the repository at this point in the history
handle plain coordinates in neuprint_list2df
  • Loading branch information
jefferis committed Sep 7, 2023
2 parents 1bf392f + 8ee9d4a commit 229a4e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
15 changes: 7 additions & 8 deletions R/fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down
23 changes: 14 additions & 9 deletions tests/testthat/test-fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,53 @@ 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,
"Rhubarb 3",
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,
"Rhubarb 8",
1232478011L,
NULL,
38389L,
1L
1L,
as.list(1:3)
)
)
)
Expand Down
Binary file modified tests/testthat/testdata/neuprint_list2df.rds
Binary file not shown.

0 comments on commit 229a4e3

Please sign in to comment.