salesforcer (version 0.2.2)

compact2: Remove all zero-length elements from list ignoring AsIs elements

Description

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.

Usage

compact2(.x, .p = identity)

Arguments

.x

list or vector

.p

function; predicate function that identifies elements to discard

Value

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.