Skip to content

Commit

Permalink
Merge pull request #39 from sanchit-saini/unsplit-fix
Browse files Browse the repository at this point in the history
Update unsplit() to properly handle named List
  • Loading branch information
lawremi authored May 4, 2021
2 parents a5258ca + 99fc99d commit 4944187
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions R/seqapply.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ setMethod("unsplit", "List", function(value, f, drop = FALSE) {
if (NROW(value_flat) != length(f))
stop("Length of 'unlist(value)' must equal length of 'f'")
splitAsList(value_flat, f, drop = drop) <- value
if (!is.null(names(value_flat))) {
nms <- relist(names(value_flat), value)
splitAsList(names(value_flat), f, drop = drop) <- nms
}
value_flat
})

Expand Down
11 changes: 10 additions & 1 deletion inst/unitTests/test_seqapply.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ test_unsplit <- function() {

v <- 1:5
l <- splitAsList(v, f)
checkIdentical(unsplit(l, Rle(f)), v)
checkIdentical(unsplit(l, Rle(f)), v)

names(ir) <- letters[1:5]
rl <- split(ir, f)
checkIdentical(unsplit(rl, f), ir)

ir <- IRanges(1:5, 11:15)
names(ir)[c(1,3,5)] <- letters[1:3]
rl <- split(ir, f)
checkIdentical(unsplit(rl, f), ir)
}

0 comments on commit 4944187

Please sign in to comment.