Skip to content

Commit

Permalink
Remove type is multi in combine_keys()
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Aug 27, 2020
1 parent 6891ec6 commit 90870b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 129 deletions.
21 changes: 1 addition & 20 deletions R/parse-query.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,7 @@ combine_keys <- function(obj, type) {
function(x) {
unname(unlist(x))
},
"multi" =
function(x) {
if (length(x) == 1) {
# return first item only
return(x[[1]])
}

# return list of internal named items
# aka... unlist the top layer only. Maintain the inner layer names
x_new <- lapply(unname(x), function(x_item) {
if (is.atomic(x_item)) {
# handles things like `parse_text` which returns atomic values
return(list(x_item))
}

# handles things like `parse_octet` which returns a (possibly) named list
x_item
})
as.list(unlist(x_new, recursive = FALSE))
}
stop("unknown type: ", type)
)

# equivalent code output, `split` is much faster with larger objects
Expand Down
109 changes: 0 additions & 109 deletions tests/testthat/test-combine-keys.R

This file was deleted.

5 changes: 5 additions & 0 deletions tests/testthat/test-querystring.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ test_that("different lengths of query string return same shape", {

}
})

test_that("query keys with same name are combined", {
a <- list(A = 1, A = 2, B = 3, A = 4, B = 5)
expect_equal(combine_keys(a, "query"), list(A = c(1,2,4), B = c(3,5)))
})

0 comments on commit 90870b4

Please sign in to comment.