<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/bigrquery-0-4-0/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.rstudio.org/2017/06/26/bigrquery-0-4-0/"> RStudio Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I’m pleased to announce that bigrquery 0.4.0 is now on CRAN. bigrquery makes it possible to talk to <a rel="nofollow" href="https://cloud.google.com/bigquery/" target="_blank">Google’s BigQuery</a> cloud database. It provides both <a rel="nofollow" href="https://cloud.google.com/bigquery/" target="_blank">DBI</a> and <a rel="nofollow" href="http://dplyr.tidyverse.org/" target="_blank">dplyr</a> backends so you can interact with BigQuery using either low-level SQL or high-level dplyr verbs.</p>
<p>Install the latest version of bigrquery with:</p>
<pre><code><span>install.packages</span><span>(</span><span>&quot;bigrquery&quot;</span><span>)</span></code></pre>
<div>
<h2>Basic usage</h2>
<p>Connect to a bigquery database using DBI:</p>
<pre><code><span>library</span><span>(</span><span>dplyr</span><span>)</span>

<span>con</span> <span>&lt;-</span> <span>DBI</span><span>:</span><span>:</span><span>dbConnect</span><span>(</span><span>dbi_driver</span><span>(</span><span>)</span>,
  <span>project</span> <span>=</span> <span>&quot;publicdata&quot;</span>,
  <span>dataset</span> <span>=</span> <span>&quot;samples&quot;</span>,
  <span>billing</span> <span>=</span> <span>&quot;887175176791&quot;</span>
<span>)</span>
<span>DBI</span><span>:</span><span>:</span><span>dbListTables</span><span>(</span><span>con</span><span>)</span>
<span>#> [1] &quot;github_nested&quot; &quot;github_timeline&quot; &quot;gsod&quot; &quot;natality&quot; </span>
<span>#> [5] &quot;shakespeare&quot; &quot;trigrams&quot; &quot;wikipedia&quot;</span></code></pre>
<p>(You’ll be prompted to authenticate interactively, or you can use a service token with <code>set_service_token()</code>.)</p>
<p>Then you can either submit your own SQL queries or use dplyr to write them for you:</p>
<pre><code><span>shakespeare</span> <span>&lt;-</span> <span>con</span> <span>%>%</span> <span>tbl</span><span>(</span><span>&quot;shakespeare&quot;</span><span>)</span>
<span>shakespeare</span> <span>%>%</span>
  <span>group_by</span><span>(</span><span>word</span><span>)</span> <span>%>%</span>
  <span>summarise</span><span>(</span><span>n</span> <span>=</span> <span>sum</span><span>(</span><span>word_count</span><span>)</span><span>)</span>
<span>#> 0 bytes processed</span>
<span>#> # Source: lazy query [?? x 2]</span>
<span>#> # Database: BigQueryConnection</span>
<span>#> word n</span>
<span>#> </span></code></pre></div>