Skip to content

Commit

Permalink
Merge pull request #785 from DyfanJones/transpose_list
Browse files Browse the repository at this point in the history
Transpose list
  • Loading branch information
DyfanJones authored May 15, 2024
2 parents d28c3e7 + 9470f3f commit 44a320c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion paws.common/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: paws.common
Type: Package
Title: Paws Low-Level Amazon Web Services API
Version: 0.7.2
Version: 0.7.3
Authors@R: c(
person("David", "Kretch", email = "david.kretch@gmail.com", role = "aut"),
person("Adam", "Banker", email = "adam.banker39@gmail.com", role = "aut"),
Expand Down
3 changes: 3 additions & 0 deletions paws.common/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# paws.common 0.7.3
* fix `xml_parse` to correctly parse empty elements (#783) thanks to @stevepowell99 for raising issue

# paws.common 0.7.2
* improve performance of `restxml_unmarshal` by x3
* fix `rest_unmarshal_location_elements` only skip header if location is not found (#761)
Expand Down
11 changes: 9 additions & 2 deletions paws.common/R/xmlutil.R
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ xml_parse_structure <- function(xml_elts, interface_i, tags_i, tag_type = NULL,
# the `is.list()` check is necessary because e.g. `CheckSumAlgorithm` has
# a list interface though it isn't a list?!
if (isTRUE(flattened) && is.list(result)) {
result <- .mapply(list, result, NULL)
result <- transpose(result)
} else {
result <- as.list(result)
}
Expand Down Expand Up @@ -358,7 +358,7 @@ xml_parse_list <- function(xml_elts, interface_i, tags_i, tag_type = NULL, flatt
# the `is.list()` check is necessary because e.g. `CheckSumAlgorithm` has
# a list interface though it isn't a list?!
if (isTRUE(flattened) && is.list(result)) {
result <- .mapply(list, result, NULL)
result <- transpose(result)
}

return(result)
Expand Down Expand Up @@ -460,3 +460,10 @@ default_parse_scalar <- function(interface_i, tag_type = NULL) {
)
return(result)
}

transpose <- function(x) {
if (any(found <- lengths(x) == 0)) {
x[found] <- list(rep(list(), length.out = length(x[[1]])))
}
.mapply(list, x, NULL)
}
2 changes: 1 addition & 1 deletion paws.common/cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Submission
This release contains bug fixes and minor performance enhancements
This release contains a hotfix.

## Test environments

Expand Down
17 changes: 17 additions & 0 deletions paws.common/tests/testthat/test_xmlutil.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,20 @@ test_that("check nested xml build with nested default parameters", {
actual <- xml_build(params_nested)
expect_equal(actual, list(nested = list(cho = list(""))))
})

test_that("check if list is transposed correctly", {
obj <- list(
var1 = c(1, 2, 3),
var2 = letters[1:3],
var3 = list(),
var4 = list()
)
expected <- list(
list(var1 = 1, var2 = "a", var3 = NULL, var4 = NULL),
list(var1 = 2, var2 = "b", var3 = NULL, var4 = NULL),
list(var1 = 3, var2 = "c", var3 = NULL, var4 = NULL)
)
actual <- transpose(obj)

expect_equal(actual, expected)
})

0 comments on commit 44a320c

Please sign in to comment.