https://github.com/cran/bayestestR
Revision 01482dc32c49cc56111762e704c854b5f287966a authored by Dominique Makowski on 20 April 2020, 05:10:28 UTC, committed by cran-robot on 20 April 2020, 05:10:28 UTC
1 parent 645c10f
Tip revision: 01482dc32c49cc56111762e704c854b5f287966a authored by Dominique Makowski on 20 April 2020, 05:10:28 UTC
version 0.6.0
version 0.6.0
Tip revision: 01482dc
utils_flatten_list.R
#' Flatten a list
#'
#' @param object A list.
#' @param name Name of column of keys in the case the output is a dataframe.
#' @keywords internal
.flatten_list <- function(object, name = "name") {
if (length(object) == 1) {
object[[1]]
} else if (all(sapply(object, is.data.frame))) {
if (is.null(names(object))) {
as.data.frame(t(sapply(object, rbind)))
} else {
tryCatch(
{
rn <- names(object)
object <- do.call(rbind, object)
object[name] <- rn
object[c(name, setdiff(names(object), name))]
},
warning = function(w) {
object
},
error = function(e) {
object
}
)
}
} else {
object
}
}
Computing file changes ...