How can I remove empty elements from a list that contain zero length pairlist as
character(0), integer(0) etc...
list2
# $`hsa:7476
For the sake of completeness, the purrr package from the popular tidyverse has some useful functions for working with lists - compact (introduction) does the trick, too, and works fine with magrittr's %>% pipes:
l <- list(1:3, "foo", character(0), integer(0))
library(purrr)
compact(l)
# [[1]]
# [1] 1 2 3
#
# [[2]]
# [1] "foo"
or
list(1:3, "foo", character(0), integer(0)) %>% compact