Skip to content

Commit 44a320c

Browse files
authored
Merge pull request #785 from DyfanJones/transpose_list
Transpose list
2 parents d28c3e7 + 9470f3f commit 44a320c

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

paws.common/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: paws.common
22
Type: Package
33
Title: Paws Low-Level Amazon Web Services API
4-
Version: 0.7.2
4+
Version: 0.7.3
55
Authors@R: c(
66
person("David", "Kretch", email = "[email protected]", role = "aut"),
77
person("Adam", "Banker", email = "[email protected]", role = "aut"),

paws.common/NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# paws.common 0.7.3
2+
* fix `xml_parse` to correctly parse empty elements (#783) thanks to @stevepowell99 for raising issue
3+
14
# paws.common 0.7.2
25
* improve performance of `restxml_unmarshal` by x3
36
* fix `rest_unmarshal_location_elements` only skip header if location is not found (#761)

paws.common/R/xmlutil.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ xml_parse_structure <- function(xml_elts, interface_i, tags_i, tag_type = NULL,
289289
# the `is.list()` check is necessary because e.g. `CheckSumAlgorithm` has
290290
# a list interface though it isn't a list?!
291291
if (isTRUE(flattened) && is.list(result)) {
292-
result <- .mapply(list, result, NULL)
292+
result <- transpose(result)
293293
} else {
294294
result <- as.list(result)
295295
}
@@ -358,7 +358,7 @@ xml_parse_list <- function(xml_elts, interface_i, tags_i, tag_type = NULL, flatt
358358
# the `is.list()` check is necessary because e.g. `CheckSumAlgorithm` has
359359
# a list interface though it isn't a list?!
360360
if (isTRUE(flattened) && is.list(result)) {
361-
result <- .mapply(list, result, NULL)
361+
result <- transpose(result)
362362
}
363363

364364
return(result)
@@ -460,3 +460,10 @@ default_parse_scalar <- function(interface_i, tag_type = NULL) {
460460
)
461461
return(result)
462462
}
463+
464+
transpose <- function(x) {
465+
if (any(found <- lengths(x) == 0)) {
466+
x[found] <- list(rep(list(), length.out = length(x[[1]])))
467+
}
468+
.mapply(list, x, NULL)
469+
}

paws.common/cran-comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Submission
2-
This release contains bug fixes and minor performance enhancements
2+
This release contains a hotfix.
33

44
## Test environments
55

paws.common/tests/testthat/test_xmlutil.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,20 @@ test_that("check nested xml build with nested default parameters", {
7070
actual <- xml_build(params_nested)
7171
expect_equal(actual, list(nested = list(cho = list(""))))
7272
})
73+
74+
test_that("check if list is transposed correctly", {
75+
obj <- list(
76+
var1 = c(1, 2, 3),
77+
var2 = letters[1:3],
78+
var3 = list(),
79+
var4 = list()
80+
)
81+
expected <- list(
82+
list(var1 = 1, var2 = "a", var3 = NULL, var4 = NULL),
83+
list(var1 = 2, var2 = "b", var3 = NULL, var4 = NULL),
84+
list(var1 = 3, var2 = "c", var3 = NULL, var4 = NULL)
85+
)
86+
actual <- transpose(obj)
87+
88+
expect_equal(actual, expected)
89+
})

0 commit comments

Comments
 (0)