Extract elements by name from a nested list
<p>For a named, nested list, what is the best way to extract a specific element? If I have a list with known fields (eg, from a yaml file), I want to extract an element (list or otherwise) without having to search through the names and indices or trying to keep track of the levels in the <code>str</code> output.</p>

<p>For example, I know that <code>lm</code> returns a nested list which contains <code>qr</code> info.</p>

<pre><code>fit &lt;- lm(mpg ~ wt, mtcars)
fit$qr$qraux
# [1] 1.176777 1.046354
</code></pre>

<p>But if I don't know the order, I just want to specify the list along with the name of the element. Ideally, something would give me both the path of indices to the element <em>and</em> path of names to the element <em>and</em> the element itself.</p>

<p><a href="https://stackoverflow.com/questions/13016359/how-to-directly-select-the-same-column-from-all-nested-lists-within-a-list">Related</a>, <a href="https://stackoverflow.com/questions/31613880/getting-nested-elements-from-a-list">related</a>, <a href="https://stackoverflow.com/questions/27890388/r-get-element-by-name-from-a-nested-list">related</a></p>