Skip to content
Prev 61171 / 63421 Next

unlist preserve common class?

Hi Spencer,

Another, potentially somewhat less disruptive/more general option would be
to add a stop.at.object or stop.at.nonlist (or alternatively list.only)
argument, which would basically translate to "collapse the list structure
to flat, but don't try to combine the leaf elements within the list. You
could then do whatever you wanted to said now-flat list as a second call.

i.e.,

flatlist <- unlist(structured_list, list.only = TRUE)
final_res <- cool_combiner_fun(flatlist)

I had to do something similar years ago when I was implementing xpath for
arbitrary R objects, because you can, e.g., always get x[1] out of x
infinitely many times, so I defined "Stopping functions". The fully general
case would be to do the same here, and accept, e.g., stopping.cond, but
that is probably too complex for unlist and might simply belong as a
completely separate function.

Best,
~G

On Thu, Dec 8, 2022 at 8:21 PM Spencer Graves <
spencer.graves at effectivedefense.org> wrote: