This function wraps the compact function to recursively
remove elements from lists that have zero length, but spares the elements wrapped
in I which mean something specific when passing as JSON.
compact2(.x, .p = identity)list or vector
function; predicate function that identifies elements to discard
list containing no empty elements, but does leave anything that
has been wrapped in I() making the class AsIs which signals
to toJSON not to drop the value, but to set as null.