Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (21 sloc) 534 Bytes
#' List to vector.
#'
#' Reduce/simplify a list of homogenous objects to a vector
#'
#' @param res list of input data
#' @keywords internal
#' @family list simplification functions
list_to_vector <- function(res) {
n <- length(res)
if (n == 0) return(vector())
if (n == 1) return(res[[1]])
atomic <- sapply(res, is.atomic)
if (all(atomic)) {
numeric <- all(unlist(lapply(res, is.numeric)))
classes <- unique(lapply(res, class))
if (numeric || length(classes) == 1) {
res <- unlist(res)
}
}
res
}
Something went wrong with that request. Please try again.