<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/the-trouble-with-tibbles/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.jumpingrivers.com/posts/2018/trouble_with_tibbles/"> R on The Jumping Rivers Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<ul>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2018/trouble_with_tibbles/#what-are-tibbles" target="_blank">What are tibbles?</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2018/trouble_with_tibbles/#precursors" target="_blank">Precursors</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2018/trouble_with_tibbles/#tribblemaking" target="_blank">Tribblemaking</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2018/trouble_with_tibbles/#tibbles-vs-data-frames" target="_blank">Tibbles vs Data Frames</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2018/trouble_with_tibbles/#disadvantages" target="_blank">Disadvantages</a></li>
<li><a rel="nofollow" href="http://blog.jumpingrivers.com/posts/2018/trouble_with_tibbles/#to-summarise.." target="_blank">To summarise..</a></li>
</ul>
</div>
<p>Let’s get something straight, there isn’t really any trouble with tibbles. I’m hoping you’ve noticed this is a play on 1967 <a rel="nofollow" href="https://en.wikipedia.org/wiki/The_Trouble_with_Tribbles" target="_blank">Star Trek episode</a>, “The Trouble with Tribbles”. I’ve recently got myself a job as a Data Scientist, here, at <a rel="nofollow" href="https://www.jumpingrivers.com/" target="_blank">Jumping Rivers</a>. Having never come across tibbles until this point, I now find myself using them in nearly every R script I compose. Be that your timeless standard R script, your friendly Shiny app or an analytical Markdown document.</p>
<div>
<h2>What are tibbles?</h2>
<p>Presumably this is why you came here, right?</p>
<p>Tibbles are a modern take on data frames, but crucially they are <em>still</em> data frames. Well, what’s the difference then? There’s a quote I found somewhere on the internet that decribes the difference quite well;</p>
<p><em>“keeping what time has proven to be effective, and throwing out what is not”</em>.</p>
<p>Basically, some clever people took the classic <code>data.frame()</code>, shook it til the ineffective parts fell out, then added some new, more appropriate features.</p>
</div>
<div>
<h2>Precursors</h2>
<pre><code># The easiest way to get access is to isstall the tibble package.
install.packages(&quot;tibble&quot;)

# Alternatively, tibbles are a part of the tidyverse and hence installing the whole tidyverse will give you access.
install.packages(&quot;tidverse&quot;)</code></pre>
<pre><code># I am just going to use tibble.
library(tibble)</code></pre>
</div>
<div>
<h2>Tribblemaking</h2>
<p>There are three ways to form a tibble. It pretty much acts as your friendly old pal <code>data.frame()</code> does. Just like standard data frames, we can create tibbles, coerce objects into tibbles and import data sets into <code>R</code> as a tibble. Below is a table of the traditional <code>data.frame()</code> commands and their respective <strong>tidyverse</strong> commands.</p>
<table>
<thead>
<tr>
<th>Formation Type</th>
<th>Data Frame Commands</th>
<th>Tibbles Commands</th>
</tr>
</thead>
<tbody>
<tr>
<td><em>Creation</em></td>
<td><code>data.frame()</code></td>
<td><code>data_frame()</code> <code>tibble()</code> <code>tribble()</code></td>
</tr>
<tr>
<td><em>Coercion</em></td>
<td><code>as.data.frame()</code></td>
<td><code>as_data_frame()</code> <code>as_tibble()</code></td>
</tr>
<tr>
<td><em>Importing</em></td>
<td><code>read.*()</code></td>
<td><code>read_delim()</code> <code>read_csv()</code> <code>read_csv2()</code> <code>read_tsv()</code></td>
</tr>
</tbody>
</table>
<p>Let’s take a closer look…</p>
<div>
<h4>1) Creation.</h4>
<p>Just as <code>data.frame()</code> creates data frames,<code>tibble()</code>, <code>data_frame()</code> and <code>tribble()</code> all create tibbles.</p>
<p>Standard data frame.</p>
<pre><code>data.frame(a = 1:5, b = letters[1:5])  
##   a b
## 1 1 a
## 2 2 b
## 3 3 c
## 4 4 d
## 5 5 e</code></pre>
<p>A tibble using <code>tibble()</code> (identical to using <code>data_frame</code>).</p>
<pre><code>tibble(a = 1:5, b = letters[1:5])
## # A tibble: 5 x 2
##       a b    
##   </code></pre></div></div>