azadag
5/4/2020 - 12:37 AM

flatten a list with NULL values

sapply(a,function(x) ifelse(is.null(x),NA,x))

# or
a[sapply(a, is.null)] <- NA
unlist(a)

# purrr
list('a','b',NULL) %>% purrr::map(.x=., ~ifelse(is.null(.x), NA, .x))

## or 
list('hi','hello', NULL) %>% 
lapply(function(x) ifelse(is.null(x), NA, x)) %>% 
purrr::flatten_chr()