You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would this map over the deepest level or all leaf nodes? The latter (or some other intelligible version of rapply) could be really useful for parsing deeply nested data coming from JSON or the like.
@alistaire47 yes I was thinking at_bottom() would apply a function to leaves. We could have map_tree() to apply a function to all nodes, then at_bottom() would be implemented as:
x %>% map_tree_if(is_atomic, fn)
And maybe have map_tree_until(), which would not inspect further the nodes for which the predicate returns FALSE, which could be useful for applying a function to list-like S3 objects.
Activity
lionel- commentedon Sep 1, 2016
On that note I wonder if the following would be good UI:
lionel- commentedon Sep 15, 2016
Other useful idiom for tree structures: visit each node twice. Once on the way in, the second time on the way back. See https://stlab.adobe.com/group__asl__tutorials__forest.html
The mapped function would get a boolean indicating if this is the second time we see the node.
alistaire47 commentedon Feb 10, 2017
Would this map over the deepest level or all leaf nodes? The latter (or some other intelligible version of
rapply) could be really useful for parsing deeply nested data coming from JSON or the like.lionel- commentedon Feb 26, 2017
http://okmij.org/ftp/continuations/zipper.html
lionel- commentedon Feb 26, 2017
@alistaire47 yes I was thinking
at_bottom()would apply a function to leaves. We could havemap_tree()to apply a function to all nodes, thenat_bottom()would be implemented as:And maybe have
map_tree_until(), which would not inspect further the nodes for which the predicate returnsFALSE, which could be useful for applying a function to list-like S3 objects.[-]at_bottom()[/-][+]Mapping over trees[/+]hadley commentedon Mar 5, 2017
What if instead of
at_bottom(.x, .f)you simply didat_depth(.x, -1, .f)?And what if
at_depth()was instead calledmodify_depth()? And to match the othermodify()functions was calledmodify_depth()?hadley commentedon Mar 5, 2017
I also wonder about an option to
at_depth()that gives you this behaviour:So that if the list is ragged, you can choose to only operate on lists at a certain level, ignoring branches that aren't that deep.
Add .ragged & support negative depths