<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reuse Tidy Datasets • pins</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/all.min.css" integrity="sha256-nAmazAk6vS34Xqo0BSrTb+abbtFlgsFK7NKSi6o7Y78=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/v4-shims.min.css" integrity="sha256-6qHlizsOWFskGlwVOKuns+D1nB6ssZrHQrNj1wGplHc=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/headroom.min.js" integrity="sha256-DJFC1kqIhelURkuza0AvYal5RxMtpzLjFhsnVIeuk+U=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../../pkgdown.css" rel="stylesheet">
<script src="../../pkgdown.js"></script><link href="../../extra.css" rel="stylesheet">
<meta property="og:title" content="Reuse Tidy Datasets">
<meta property="og:description" content="">
<meta property="og:image" content="/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
    <div class="container template-article">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../../index.html">pins</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.4.2</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../../index.html">Home</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Articles
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Pins</li>
    <li>
      <a href="../../articles/pins-starting.html">Getting Started</a>
    </li>
    <li>
      <a href="../../articles/pins-rstudio.html">Using Pins in RStudio</a>
    </li>
    <li class="divider">
    <li class="dropdown-header">Boards</li>
    <li>
      <a href="../../articles/boards-understanding.html">Understanding Boards</a>
    </li>
    <li>
      <a href="../../articles/boards-azure.html">Azure</a>
    </li>
    <li>
      <a href="../../articles/boards-dospace.html">DigitalOcean</a>
    </li>
    <li>
      <a href="../../articles/boards-github.html">GitHub</a>
    </li>
    <li>
      <a href="../../articles/boards-gcloud.html">Google Cloud</a>
    </li>
    <li>
      <a href="../../articles/boards-kaggle.html">Kaggle</a>
    </li>
    <li>
      <a href="../../articles/boards-rsconnect.html">RStudio Connect</a>
    </li>
    <li>
      <a href="../../articles/boards-s3.html">S3</a>
    </li>
    <li>
      <a href="../../articles/boards-websites.html">Websites</a>
    </li>
    <li class="divider">
    <li class="dropdown-header">Advanced</li>
    <li>
      <a href="../../articles/advanced-versions.html">Versioning</a>
    </li>
    <li class="divider">
    <li class="dropdown-header">Extensions</li>
    <li>
      <a href="../../articles/pins-extending.html">Extending Pins</a>
    </li>
    <li>
      <a href="../../articles/boards-extending.html">Extending Boards</a>
    </li>
  </ul>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Use Cases
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Overview</li>
    <li>
      <a href="../../articles/use-cases.html">Use Cases</a>
    </li>
    <li class="divider">
    <li class="dropdown-header">Use Cases</li>
    <li>
      <a href="../../articles/use-cases/reuse-tidy-datasets.html">Reuse Tidy Datasets</a>
    </li>
    <li>
      <a href="../../articles/use-cases/automate-dataset-updates.html">Automate Dataset Updates</a>
    </li>
    <li>
      <a href="../../articles/use-cases/create-data-pipelines.html">Create Data Pipelines</a>
    </li>
    <li>
      <a href="../../articles/use-cases/update-plumber-and-shiny-apps.html">Update Plumber and Shiny Apps</a>
    </li>
  </ul>
</li>
<li>
  <a href="../../reference/index.html">Reference</a>
</li>
<li>
  <a href="../../news/index.html">News</a>
</li>
<li>
  <a href="../../blog/index.html">Blog</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://github.com/rstudio/pins">
    <span class="fab fa fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      

      </header><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1>Reuse Tidy Datasets</h1>
            
      
      <small class="dont-index">Source: <a href="https://github.com/rstudio/pins/blob/master/vignettes/use-cases/reuse-tidy-datasets.Rmd"><code>vignettes/use-cases/reuse-tidy-datasets.Rmd</code></a></small>
      <div class="hidden name"><code>reuse-tidy-datasets.Rmd</code></div>

    </div>

    
    
<p>This notebook showcases the <code>pins</code> package ability to help you share and reuse tidy datasets with others. We will make use of the “A Million News Headlines” dataset from <a href="https://www.kaggle.com/therohk/million-headlines">kaggle.com/therohk/million-headlines</a>.</p>
<p>As a start, lets retrieve the dataset using <code>pins</code> and load it using <code>readr</code>. You will need to authenticate to Kaggle by downloading your token file from <a href="https://www.kaggle.com/me/account">kaggle.com/me/account</a>.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span>(pins)</a>
<a class="sourceLine" id="cb1-2" title="2"><span class="kw"><a href="../../reference/board_register_kaggle.html">board_register_kaggle</a></span>(<span class="dt">token =</span> <span class="st">"path/to/kaggle.json"</span>)</a>
<a class="sourceLine" id="cb1-3" title="3"></a>
<a class="sourceLine" id="cb1-4" title="4">news &lt;-<span class="st"> </span><span class="kw"><a href="../../reference/pin_get.html">pin_get</a></span>(<span class="st">"therohk/million-headlines"</span>, <span class="dt">board =</span> <span class="st">"kaggle"</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb1-5" title="5"><span class="st">  </span>readr<span class="op">::</span><span class="kw"><a href="https://readr.tidyverse.org/reference/read_delim.html">read_csv</a></span>()</a>
<a class="sourceLine" id="cb1-6" title="6"></a>
<a class="sourceLine" id="cb1-7" title="7">news</a></code></pre></div>
<pre><code># A tibble: 1,103,663 x 2
   publish_date headline_text                                     
          &lt;dbl&gt; &lt;chr&gt;                                             
 1     20030219 aba decides against community broadcasting licence
 2     20030219 act fire witnesses must be aware of defamation    
 3     20030219 a g calls for infrastructure protection summit    
 4     20030219 air nz staff in aust strike for pay rise          
 5     20030219 air nz strike to affect australian travellers     
 6     20030219 ambitious olsson wins triple jump                 
 7     20030219 antic delighted with record breaking barca        
 8     20030219 aussie qualifier stosur wastes four memphis match 
 9     20030219 aust addresses un security council over iraq      
10     20030219 australia is locked into war timetable opp        
# … with 1,103,653 more rows</code></pre>
<p>First, let’s clean up this dataset. For instance, the ‘publish_date’ column is a character, not a date:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span>(dplyr)</a>
<a class="sourceLine" id="cb3-2" title="2"></a>
<a class="sourceLine" id="cb3-3" title="3">news_cleaned &lt;-<span class="st"> </span>news <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-4" title="4"><span class="st">  </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">publish_date =</span> <span class="kw"><a href="https://rdrr.io/r/base/as.Date.html">as.Date</a></span>(<span class="kw"><a href="https://rdrr.io/r/base/character.html">as.character</a></span>(publish_date), <span class="dt">format =</span> <span class="st">"%Y%m%d"</span>))</a>
<a class="sourceLine" id="cb3-5" title="5"></a>
<a class="sourceLine" id="cb3-6" title="6">news_cleaned</a></code></pre></div>
<pre><code># A tibble: 1,103,663 x 2
   publish_date headline_text                                     
   &lt;date&gt;       &lt;chr&gt;                                             
 1 2003-02-19   aba decides against community broadcasting licence
 2 2003-02-19   act fire witnesses must be aware of defamation    
 3 2003-02-19   a g calls for infrastructure protection summit    
 4 2003-02-19   air nz staff in aust strike for pay rise          
 5 2003-02-19   air nz strike to affect australian travellers     
 6 2003-02-19   ambitious olsson wins triple jump                 
 7 2003-02-19   antic delighted with record breaking barca        
 8 2003-02-19   aussie qualifier stosur wastes four memphis match 
 9 2003-02-19   aust addresses un security council over iraq      
10 2003-02-19   australia is locked into war timetable opp        
# … with 1,103,653 more rows</code></pre>
<p>Let’s also assume we are interested in understanding when news outlets publish news, not what headlines are published. For this, we can keep the counts per day and month and throw away the other columns:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" title="1">news_totals &lt;-<span class="st"> </span>news_cleaned <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb5-2" title="2"><span class="st">  </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(publish_date) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb5-3" title="3"><span class="st">  </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarize</a></span>(<span class="dt">count =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/n.html">n</a></span>())</a></code></pre></div>
<p>We can now plot by month the total amount of news being produced by this news outlet:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span>(ggplot2)</a>
<a class="sourceLine" id="cb6-2" title="2"></a>
<a class="sourceLine" id="cb6-3" title="3">news_totals <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb6-4" title="4"><span class="st">  </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="dt">publish_date =</span> lubridate<span class="op">::</span><span class="kw"><a href="http://lubridate.tidyverse.org/reference/round_date.html">floor_date</a></span>(publish_date, <span class="st">"year"</span>)) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb6-5" title="5"><span class="st">  </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarize</a></span>(<span class="dt">count =</span> <span class="kw"><a href="https://rdrr.io/r/base/sum.html">sum</a></span>(count)) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb6-6" title="6"><span class="st">  </span><span class="kw"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span>(<span class="kw"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span>(<span class="dt">x=</span>publish_date, <span class="dt">y=</span>count)) <span class="op">+</span></a>
<a class="sourceLine" id="cb6-7" title="7"><span class="st">  </span><span class="kw"><a href="https://ggplot2.tidyverse.org/reference/geom_path.html">geom_line</a></span>() </a></code></pre></div>
<p><img src="images/reuse-analysis-ggplot2.png" style="width:70.0%"></p>
<p>Now, while this might complete our particular analysis, others in your team might be interested in easily fetching your tidy dataset, which you can now easily share with <code>pins</code> in any available board. The following example uses RStudio Connect but this board can also be replaced to use Kaggle, GitHub or even custom boards:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1">pins<span class="op">::</span><span class="kw"><a href="https://rdrr.io/pkg/pins/man/pin.html">pin</a></span>(news_totals, <span class="dt">board =</span> <span class="st">"rsconnect"</span>)</a></code></pre></div>
<p><a href="https://beta.rstudioconnect.com/connect/#/apps/6522/access"><img src="images/reuse-analysis-rsconnect.png"></a></p>
<p>You can then use the board’s user interface to share this pin with others. A colleague can now reuse your tidy dataset by fetching it from the given board using pins:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1"><span class="kw"><a href="../../reference/pin_get.html">pin_get</a></span>(<span class="st">"news-totals"</span>, <span class="dt">board =</span> <span class="st">"rsconnect"</span>)</a></code></pre></div>
<pre><code># A tibble: 5,422 x 2
   publish_date count
   &lt;date&gt;       &lt;int&gt;
 1 2003-02-19     198
 2 2003-02-20     250
 3 2003-02-21     250
 4 2003-02-22     126
 5 2003-02-23     136
 6 2003-02-24     250
 7 2003-02-25     250
 8 2003-02-26     250
 9 2003-02-27     222
10 2003-02-28     249
# … with 5,412 more rows</code></pre>
<p>You can preview the RStudio Connect pin for this tidy dataset at <a href="https://beta.rstudioconnect.com/connect/#/apps/6522/access">beta.rstudioconnect.com/connect/#/apps/6522/access</a>.</p>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
      </div>

</div>



      <footer><div class="copyright">
  <p>Developed by Javier Luraschi.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.4.1.</p>
</div>

      </footer>
</div>

  


  </body>
</html>
