Here are two ways to do what you want. One is more general and involved, second is doing exactly what you want, but won't work with, for example, more deeply-nested lists.
library(tidyverse)
x <- list(list(c("A", "B"), NA, NA, NA),
list(c("C","E"), NA, "D", NA, NA))
remove_empty <- function(x){
if(is.list(x)) {
x %>%
purrr::discard(rlang::is_na) %>%
purrr::map(remove_empty)
} else {
x
}
}
intended.answer <- list(list(c("A", "B")),
list(c("C","E"),"D"))
res1 <- x %>% map(., discard, .p = rlang::is_na)
res2 <- remove_empty(x)
all.equal(intended.answer, res1)
#> [1] TRUE
all.equal(intended.answer, res2)
#> [1] TRUE
Created on 2019-02-07 by the reprex package (v0.2.1)