title: R: all combinations of nested list of variable length
body: <p>I am sure this must have a solution somewhere here but I really failed to find it. There is something along the same <a href="https://stackoverflow.com/questions/57448008/how-to-create-all-combinations-from-a-nested-list-while-preserving-the-structure">here</a>, but then not really.
  Say I have a nested list of variable lengths - below length is 2:</p>
  
  <p><code>L = list('Z1' = c('z11', 'z12'), 'Z2' = c('z21', 'z22', 'z23'))</code></p>
  
  <p>How do I get in base R all combinations of sublists. For short lists like <code>L</code> one would do for instance:</p>
  
  <pre><code>&gt; expand.grid(L[[1]], L[[2]])
    Var1 Var2
  1  z11  z21
  2  z12  z21
  3  z11  z22
  4  z12  z22
  5  z11  z23
  6  z12  z23
  </code></pre>
  
  <p>But how is this achieved in the general case ?</p>