title: various functions react badly to tbl_df (data frame type used by dplyr)
body: <p>I've noticed that various functions react badly to the class <code>tbl_df</code> used by dplyr. I don't know how to predict when there will be an issue and when there won't. Converting to a native R data frame always solves the problem, but this is annoying. Is there a better approach than converting to native R data frames as needed?</p>
  
  <p>My latest example is using the <code>xtable</code> package:</p>
  
  <pre><code>&gt; library(dplyr)
  &gt; library(nycflights13)
  &gt; library(xtable)
  </code></pre>
  
  <p><code>tbl_df</code> as used by dplyr:</p>
  
  <pre><code>&gt; flights
  Source: local data frame [336,776 x 16]
  
     year month day dep_time dep_delay arr_time arr_delay carrier tailnum flight origin dest air_time distance hour minute
  1  2013     1   1      517         2      830        11      UA  N14228   1545    EWR  IAH      227     1400    5     17
  2  2013     1   1      533         4      850        20      UA  N24211   1714    LGA  IAH      227     1416    5     33
  3  2013     1   1      542         2      923        33      AA  N619AA   1141    JFK  MIA      160     1089    5     42
  4  2013     1   1      544        -1     1004       -18      B6  N804JB    725    JFK  BQN      183     1576    5     44
  5  2013     1   1      554        -6      812       -25      DL  N668DN    461    LGA  ATL      116      762    5     54
  6  2013     1   1      554        -4      740        12      UA  N39463   1696    EWR  ORD      150      719    5     54
  7  2013     1   1      555        -5      913        19      B6  N516JB    507    EWR  FLL      158     1065    5     55
  8  2013     1   1      557        -3      709       -14      EV  N829AS   5708    LGA  IAD       53      229    5     57
  9  2013     1   1      557        -3      838        -8      B6  N593JB     79    JFK  MCO      140      944    5     57
  10 2013     1   1      558        -2      753         8      AA  N3ALAA    301    LGA  ORD      138      733    5     58
  ..  ...   ... ...      ...       ...      ...       ...     ...     ...    ...    ...  ...      ...      ...  ...    ...
  </code></pre>
  
  <p><code>xtable</code> fails:</p>
  
  <pre><code>&gt; xtable(flights %&gt;% head)
  Error in .subset2(x, i, exact = exact) : subscript out of bounds
  </code></pre>
  
  <p>After conversion <code>xtable</code> is fine:</p>
  
  <pre><code>&gt; xtable(flights %&gt;% head %&gt;% data.frame)
  % latex table generated in R 3.1.1 by xtable 1.7-3 package
  % Fri Jan 16 08:53:55 2015
  \begin{table}[ht]
  \centering
  \begin{tabular}{rrrrrrrrllrllrrrr}
    \hline
   &amp; year &amp; month &amp; day &amp; dep\_time &amp; dep\_delay &amp; arr\_time &amp; arr\_delay &amp; carrier &amp; tailnum &amp; flight &amp; origin &amp; dest &amp; air\_time &amp; distance &amp; hour &amp; minute \\ 
    \hline
  1 &amp; 2013 &amp;   1 &amp;   1 &amp; 517 &amp; 2.00 &amp; 830 &amp; 11.00 &amp; UA &amp; N14228 &amp; 1545 &amp; EWR &amp; IAH &amp; 227.00 &amp; 1400.00 &amp; 5.00 &amp; 17.00 \\ 
    2 &amp; 2013 &amp;   1 &amp;   1 &amp; 533 &amp; 4.00 &amp; 850 &amp; 20.00 &amp; UA &amp; N24211 &amp; 1714 &amp; LGA &amp; IAH &amp; 227.00 &amp; 1416.00 &amp; 5.00 &amp; 33.00 \\ 
    3 &amp; 2013 &amp;   1 &amp;   1 &amp; 542 &amp; 2.00 &amp; 923 &amp; 33.00 &amp; AA &amp; N619AA &amp; 1141 &amp; JFK &amp; MIA &amp; 160.00 &amp; 1089.00 &amp; 5.00 &amp; 42.00 \\ 
    4 &amp; 2013 &amp;   1 &amp;   1 &amp; 544 &amp; -1.00 &amp; 1004 &amp; -18.00 &amp; B6 &amp; N804JB &amp; 725 &amp; JFK &amp; BQN &amp; 183.00 &amp; 1576.00 &amp; 5.00 &amp; 44.00 \\ 
    5 &amp; 2013 &amp;   1 &amp;   1 &amp; 554 &amp; -6.00 &amp; 812 &amp; -25.00 &amp; DL &amp; N668DN &amp; 461 &amp; LGA &amp; ATL &amp; 116.00 &amp; 762.00 &amp; 5.00 &amp; 54.00 \\ 
    6 &amp; 2013 &amp;   1 &amp;   1 &amp; 554 &amp; -4.00 &amp; 740 &amp; 12.00 &amp; UA &amp; N39463 &amp; 1696 &amp; EWR &amp; ORD &amp; 150.00 &amp; 719.00 &amp; 5.00 &amp; 54.00 \\ 
     \hline
  \end{tabular}
  \end{table}
  </code></pre>
  
  <p>I'm using dplyr 0.3.0.2.</p>