<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/turning-kindle-notes-into-a-tidy-data/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://rmhogervorst.nl/cleancode/blog/2017/05/08/making-kindle-highlights-tidy.html"> Clean Code</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>It is my dream to do everything with R. And we aRe almost there. We can write blogs in blogdown or bookdown, write reports in RMarkdown (thank you <a target="_blank" rel="nofollow" href="https://twitter.com/xieyihui">Yihui Xie!</a>) create interactive webpages with Shiny (thank you <a target="_blank" rel="nofollow" href="https://twitter.com/winston_chang">Winston Chang</a>). Control our lifx lights with <a target="_blank" rel="nofollow" href="https://github.com/cboettig/lifxr">lifxr</a> (great work <a target="_blank" rel="nofollow" href="http://carlboettiger.info/">Carl!</a>) and use emoticons everywhere with the emo package.</p>
<p>There is even a novel of my vision! I recently found chapter 40 of <a target="_blank" rel="nofollow" href="http://www.psi-chology.com/the-day-the-priming-stopped/">A Dr. Primestein Adventure™ The Day the Priming Stopped</a>. There is a scene in there which says:</p>
<blockquote>
<p>“This Fortress is a monumental technological achievement,” explained Professor Power. “Every aspect of the Fortress’s security is run by R.” As they arrived at the metal doors, the Professor pressed a small button on the wall to the right. “This is an elevatoR, run by its own R package.” They waited for the doors to open, but nothing happened. After a few minutes of alternately waiting and then mashing the elevatoR button, Professor Power called someone on his mobile phone. “The elevatoR is not working…what? Why would they do that?…call Hadley Wickham!…doesn’t anyone around here check packages against the development version of R before upgrading?…yes, we’ll wait.” “Someone upgraded R without permission. Should be fixed soon,” Professor Power explained.</p>
</blockquote>
<p>But enough about jokeRs and jesteRs. As it is my life long mission to do everything in R and preferably in the <a target="_blank" rel="nofollow" href="http://tidyverse.org/">tidyverse</a>, I found something that wasn’t tidy <img alt="😞" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f61e.png"> !!! Kindle notes!</p>
<h1>kindle notes and highlights.</h1>
<p>I have a 2010 kindle to read E-books on and once in a while I write a note or highlight some text in the book. If you connect your kindle to the computer you can extract the highlights by copying the file `My Clippings.txt’ to your computer.</p>
<p>This is great, it’s a text file which means you can open it on every computer and search throug the contents. However…</p>
<blockquote>
<p>It’s not tidy.</p>
</blockquote>
<p>Let’s change that. The general procedure is thus:</p>
<ol>
<li>Create a new project in Rstudio</li>
<li>Create a new folder called <code>data</code> (or don’t but really this is neat isn’t it?)</li>
<li>Copy the <code>My Clippings.txt</code> file to that <code>data</code>-folder</li>
<li>Load the tidyverse `library(tidyverse)’</li>
<li>Hammer away untill the txt file is a data frame.</li>
<li>profit?</li>
</ol>
<h3>What is in this text file?</h3>
<p>First we do some exploratory work on the file. I’ve found that the text file is structured in a particular way:</p>
<div>
<pre><code>title  (author)
- Highlight on Page 128 | Loc. 1962-68  | Added on Sunday, December 27, 2015, 03:09 PM
</code></pre></div>