title: base-R: dataframe’s with a mix of scalar and non-scalar entries
body: <p>I am building a dataframe with 1 column of range values, 2 columns of regular 1-dim scalars:</p>
  <p>desired dataframe:</p>
  <pre><code>        range       mean       sd
  1     c(2, 10)      5.5       11.11
  2     c(3, 5)       7.88      12.01
  3     c(4, 12)      8.10      13.10 
  4     c(2, 22)     18.10       3.10
  </code></pre>
  <p>The code to build the df row by row is straightforward:</p>
  <pre><code>cols = list(list(c(2,10), c(3,5), c(4,12), c(2,22)), 
              c(5.5, 7.88, 8.10, 18.10), 
              c(11.11, 12.01, 13.10, 3.10))   # data is as a list of the column values
  df = data.frame()
  for (in in 1:4) {  # iter over rows
     row = list()
     for (j in 1:3) {   # iter over cols
        row[[j]] = cols[[j]][[i]]
     }
     df = rbind(df, row)
  }
  </code></pre>
  <p>•  <strong>My problem is that the rbind fails because cols[[1]][[i]] is of type <code>range</code>, which has dim=2 (not a scalar).</strong> The code is fine if you use a scalar type for column 1.</p>
  <p>•  I understand that the <em>idea of df</em> is to be a tabular structure of scalars.</p>
  <p>•  However, suppose I want to have the structure above, because then I can reference an ij^th entry and get the full object out (usually a scalar but for column 1, I can get a range object conveniently).</p>
  <p>•  How to do this while keeping the thing as a dataframe?  Is something like #2 below possible? (Or, any better/simpler solutions!)</p>
  <ol>
  <li>One method is to convert every non-scalar entry to a string: <code> toString( cols[[j]][[i]] )</code>
  <ul>
  <li>The downside is if you want to use lose all semantic info of the object</li>
  </ul>
  </li>
  <li>I really envision having a <code>toString()-transformer</code> which gets <strong>automagically</strong> called on the non-scalar entries (say, we specify this transformer to be called for any entry of column 1) whenever the dataframe is being used in a context required for all-scalar entries (ie, printing via built-in R printing).<br />
  Here, <strong>automagically</strong> just means I do a bunch of annoying work up-front but then the usage-code comes out very neat  :D</li>
  </ol>
  <p>EDIT: an example of an automagic way (code smell warning) would be say JavaScript object’s .get() accessor — which you can override and wrap with a <code>toString(NextMethod)</code> transformer , where <code>NextMethod</code> is the super() call from R::s3</p>
  <p>Thanks in advance =)</p>