Make sure test values are named vectors

This commit is contained in:
Winston Chang
2016-11-10 15:25:40 -06:00
parent e6fec6b27d
commit dc69a2bc94
2 changed files with 17 additions and 0 deletions

View File

@@ -640,6 +640,13 @@ ShinySession <- R6Class(
}
}
# Make sure inputs, outputs, exports are all named lists (at this
# point, they could be unnamed if they are empty lists). This is so
# that the resulting object is represented as an object in JSON
# instead of an array, and so that the RDS data structure is of a
# consistent type.
values <- lapply(values, asNamedVector)
if (length(values) == 0) {
return(httpResponse(400, "text/plain",
"No exports, inputs, or outputs requested."

View File

@@ -182,6 +182,16 @@ anyUnnamed <- function(x) {
any(!nzchar(nms))
}
# Given a vector/list, returns a named vector (the labels will be blank).
asNamedVector <- function(x) {
if (!is.null(names(x)))
return(x)
names(x) <- rep.int("", length(x))
x
}
# Given two named vectors, join them together, and keep only the last element
# with a given name in the resulting vector. If b has any elements with the same
# name as elements in a, the element in a is dropped. Also, if there are any