#' List object formatter
#'
#' @description Format ElasticSearch nested list object
#' @param df The name of the nested dataframe you want to manipulate
#' @return datatframe, tibble
#' @keywords ElasticSearch
#' @import dplyr, purrr
#' @export
#' @examples modify.list(df = df$list.object)
modify.list <- function(df) {
df <- df %>%
purrr::transpose() %>%
dplyr::as_tibble() %>%
purrr::modify(~replace(.x,lengths(.x)==0,list(NA))) %>% # replace empty elements by list(NA)
purrr::modify_if(~all(lengths(.x)==1),unlist) # unlist lists that contain only items of length 1
return(df)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.