<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/a-bookdown-hello-world-twenty-one-minus-two-recipes-for-mining-twitter-with-rtweet/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2018/01/05/a-bookdown-hello-world-twenty-one-minus-two-recipes-for-mining-twitter/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://i0.wp.com/rud.is/b/wp-content/uploads/2018/01/07_graph-1.png?ssl=1" target="_blank"><img data-orig-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2018/01/07_graph-1.png?fit=1024%2C1024&amp;ssl=1" data-orig-size="1024,1024" data-medium-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2018/01/07_graph-1.png?fit=300%2C300&amp;ssl=1" data-attachment-id="7763" data-image-meta="{" data-image-description="" src="https://i0.wp.com/rud.is/b/wp-content/uploads/2018/01/07_graph-1.png?resize=780%2C780&ssl=1" data-permalink="https://rud.is/b/2018/01/05/a-bookdown-hello-world-twenty-one-minus-two-recipes-for-mining-twitter/07_graph-1/" data-large-file="https://i0.wp.com/rud.is/b/wp-content/uploads/2018/01/07_graph-1.png?fit=530%2C530&amp;ssl=1" alt="" data-image-title="07_graph-1" width="450" data-comments-opened="1" class="wp-image-7763" data-recalc-dims="1"></a></p>
<p>The new year begins with me being on the hook to crank out a book on advanced web-scraping in R by July (more on that in a future blog post). The <a rel="nofollow" href="https://bookdown.org/" target="_blank"><code>bookdown</code><img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a> package seemed to be the best way to go about doing this but I had only played with the toy/default examples of it and wanted to test out the platform with a <a rel="nofollow" href="https://en.wikipedia.org/wiki/%22Hello,_World!%22_program" target="_blank">“Hello, World”</a>-like example of a “real” book to iron out issues and avoid more refactoring later on than I know I will have to do. I’ve been on an <code>rtweet</code> kick as of late (I have no idea why) and had an e-copy of O’Reilly’s <a rel="nofollow" href="http://shop.oreilly.com/product/0636920018261.do" target="_blank">21 Recipes for Mining Twitter</a> in the their synced Dropbox folder (it was a free giveaway a few years ago) and decided to make an <code>rtweet</code> version of it in a <code>bookdown</code> project. </p>
<p>You can find the GitHub repo for it <a rel="nofollow" href="https://github.com/hrbrmstr/21-recipes" target="_blank">here</a> and the rendered version <a rel="nofollow" href="https://rud.is/books/21-recipes/" target="_blank">here</a>. NOTE: I will likely not finish the remaining two chapters (I need to spend the time on the real book <img alt="🙂" src="https://s.w.org/images/core/emoji/2.3/72x72/1f642.png" class="wp-smiley"> but will gladly add <em>you</em> as a co-author if you shoot over a PR.</p>
<p>I began with Sean Kross’ <a rel="nofollow" href="http://seankross.com/2016/11/17/How-to-Start-a-Bookdown-Book.html" target="_blank">quick start</a> and decided to work primarily in Sublime Text and use a <code>Makefile</code> to manage the build process. Since the goal was to iron out kinks for a real production book, here’s a bullet list of some tips as a result of figuring out what worked for me:</p>
<ul>
<li>Get Yihui Xie’s <a rel="nofollow" href="https://bookdown.org/yihui/bookdown/" target="_blank">book</a>. I have a physical copy but having either will help you when things get frustrating (and they do get frustrating at times)
</li>
<li>Use <code>git</code>. However you instantiate the project, use <code>git</code> source control so you don’t lose your hard work. <strong>However</strong> some directories are not tracked in <code>git</code>! You may want to modify the line with <code>*.rds</code> in <code>.gitignore</code> to be a bit less brutal if you happen to generate <code>rds</code> files outside of the project but use them in chapter examples. <strong>Also</strong>, make sure to put other, sensitive items (like <code>.httr-oauth</code>) in that <code>.gitignore</code> to avoid having to reset credentials.
</li>
<li>Use a <code>Makefile</code>. I like RStudio, but have far more editing tools in Sublime Text for book-ish work. Plus it has an easy build system manager, and I find it easier to navigate files.
</li>
<li>Make liberal use of code chunks. <a rel="nofollow" href="https://raw.githubusercontent.com/hrbrmstr/21-recipes/master/16-Crawling-Followers-to-Approximate-Potential-Influence.Rmd" target="_blank">Chapter 16</a> has a structure that I used in many of the chapters. One block for <code>library calls</code> (no caching); load fonts (hidden, and primarily for PDF rendering); named, <em>cached</em> logical sections that go with the flow of the chapter text; custom figure dimensions to ensure they come out as desired. Caching will speed up rendering time immensely.
</li>
<li>Use saved data and a mixture of <code>echo=FALSE, eval=TRUE</code>, <code>echo=TRUE, eval=FALSE</code> for things you generated outside of the book source code (because they may be long running things you don’t want to wait for even once in rendering) but want to show in the book (perhaps with slightly modified source).
</li>
<li>Despite using <code>git</code>, create a daily compressed archive of the directory tree and stick it on Dropbox (that can be part of the <code>Makefile</code>). Your work is valuable and you need to make sure it’s backed up.
</li>
<li>Learn about references. Yihui Xie’s book shows how to deal with in- and cross-chapter references, read and use them!
</li>
<li>Use a <code>bookdown::word_document2</code> vs PDF and make a custom Word template for it. The default PDF output is fine for basic things, but you’ll want to generate a better one from Word.
</li>
<li>When things stop rendering properly save your recently edited files and go back in time with <code>git</code> to a working start. This happened to me a few times as I worked across different machines. <code>git</code> makes glitches almost stress free.
</li>
<li>Use <code>rsync</code> for publishing. I need to add this to the <code>Makefile</code> but one, short command-line call can publish your work in seconds to a web server.</li>
</ul>
<p>I’ll likely have more tips as the year goes on and will have a follow-up post for using web server access logs to generate “kindle-like” reading statistics for your tomes.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rud.is/b/2018/01/05/a-bookdown-hello-world-twenty-one-minus-two-recipes-for-mining-twitter/"> R – rud.is</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/OKeLj5HgPRU" height="1"></a></div>