Janko Thyson
2011-Mar-17 11:30 UTC
[R] Retrieve an index of nested lists | Changing name delimiter in 'unlist()'
Dear list, I have to problems that are connected: PROBLEM 1 I wonder if it is somehow possible to patch the function 'unlist(use.names=TRUE)' such that you can specify an arbitrary name delimiter, e.g. "/" or "_". As I often name my variables "var.x.y", the default delimiter makes it hard to distinguish the distinct layers of a nested list after unlisting. As 'unlist()' it is called by '.Internal()', I didn't have a clue of how to find the section where the names are pasted. I'd like to use such a patched version in order to create a customized index (class: data.frame) of nested lists which should look like this name index is.top is.bottom degree a 1 TRUE FALSE 1 a/a.1 1-1 FALSE FALSE 2 a/a.1/a.1.1 1-1-1 FALSE TRUE 3 a/a.2 1-2 FALSE FALSE 2 a/a.2/a.2.1 1-2-1 FALSE TRUE 3 b 2 TRUE FALSE 1 ... Of course I could get such an index by recursively traversing the list layers, but this takes much too long. Maybe you also have another idea on how to create such an index. PROBLEM 2 I'd also like to retrieve such an index for nested environment structures. Therefore, I would either need something similar to 'unlist()' that works on environments or find something that coerces nested environments to nested lists. Again, I solved this by recursively looping over the respective environment layers, but it's too inefficient. Is there something out there that does the job via a C routine somehow? Thanks for any suggestions, Janko
Possibly Parallel Threads
- Feature request: extend functionality of 'unlist()' by args 'delim=c("/", "_", etc.)' and 'keep.special=TRUE/FALSE'
- Flattening lists and environments (was: "how to flatten a list to the same level?")
- Possible to pretty-printing using str()?
- unlist on nested pairlists
- WG: Reference classes: error with missing arguments in method calls