## 29 May 2012

### knitr, Slideshows, and Dropbox

I just noticed that Markus Gesmann has a nice post on using RStudio, knitr, Pandoc, and Slidy to create slideshows. After my recent attempt to use deck.rb to turn a Markdown/knitr file into a deck.js presentation I caved in and also decided to go with Pandoc and Slidy.

For me, Slidy produced the cleanest slides of the three formats that Pandoc supports. The presentation is here and the source is here.

The only thing I really disliked was having to use <br /> or something similar to keep the text from bunching up at the top of the slides, which looked strange when projected onto a screen. You can customise Slidy CSS files, but I haven’t got around to that yet.

In this post I don’t want to duplicate what Markus Gesmann has already done. Instead, I wanted to mention two things that I noticed/thought about while making my presentation:

• The new MathJax syntax implemented in RStudio 0.96.227 doesn’t seem to work with Pandoc. It just renders latex as if it was part of the equation rather than the qualifier to the equation begin delimiter. To get around this I just used the regular old  and  syntax.

• It’s pretty easy to host presentations with Dropbox. Just make sure all of your files are in the same folder in your Public folder. If you want output from knitr to go into and be retrieved from someplace else, you can use the desired base URL for these files by adding this code after the Pandoc title information:

{r setup, echo=FALSE}

opts_knit$set(base.url = "")   • Where base.url = "" includes the URL of the folder you want the output stored in. • All items in a folder in Dropbox’s Public folder have the same base URL. • I learned about base.url from Yihui Xie’s source code for his knitr/Markdown example on github. He uses it to save and retrieve figures from other folders on github. ### Extra: Pandoc Code I used the following Pandoc code in the Terminal to convert the .md file to Slidy: pandoc -t slidy leg_violence_present1.md -o leg_violence_present1.html -s -i -S --mathjax  ## 21 May 2012 ### Aspirational & Useful: deck.rb with RStudio/knitr & Go2Shell There has been some interest in the recent release of RStudio 0.96 and especially the ability to use combine its knitr Markdown functionality with Pandoc to integrate R and a variety of different documents types. I just wanted to add two quick things (one mostly aspirational, the other useful) ## Aspirational: Markdown/Ruby/deck.js I am currently using this combination to put together a presentation based on a recent working paper. Maybe out of procrastination I decided to see if there was any way to use knitr/Markdown to write a deck.js presentation. I generally prefer deck.js to the three Pandoc HTML presentation types (slidy, S5, and dzslides). Deck.js presentations are a pain to write, so it would be great if there was a program like Pandoc that could quickly convert a Markdown file into a deck.js presentation. I discovered that there kind of is. There is a ruby program called deck.rb. The Markdown syntax is really simple and would be familiar to Pandoc users (individual slides are demarcated with the first level header #). After you install deck.rb in the terminal with the usual:  sudo gem install deckrb  you can easily build presentations in the command line with:  deck myPresentation.md  However, I’ve classified this as aspirational since it lacks a lot of functionality that Pandoc has, including: • There really aren’t title slides. • The slideshow opens as a locally hosted webserver, and the command to build a stand alone HTML presentation doesn’t seem to work that well (hence no example included with this post). • It only allows you to use the Swiss template. • I couldn’t figure out how to easily get MathJax support to display equations. Maybe I won’t use use deck.rb for this presentation, but I will keep an eye on any developments. ## Useful Tip: Command Line/Go2Shell Since I’m on about the terminal and command line, I thought I might mention a small (free) program that is very helpful: Go2Shell. It is a little Mac application that only opens a new terminal window from the folder that you currently have open. Very useful for easily setting your terminal working directory when, for example, making Pandoc presentations. ### Maybe One of the Most Striking Examples of Regulatory Capture, Whaling Edition This is a rare non-R/my research-based post.  From Wikipedia I’ve been reading D. Graham Burnett’s The Sounding of the Whale: Science and Cetaceans in the Twentieth Century. One particularly interesting piece of information, in this generally very interesting book for anyone interested in whales, science, the history of science, conservation, regulation, international agreements … is that when the early 20th century officials at the British Colonial Office tried to make sure that the (fairly meagre) whaling restrictions around South Georgia Island were being enforced: [the official was given] a brisk lesson in South Georgia realpolitik: the [enforcement officer] ‘occupies two rooms in a cottage owned by [the main whaling company] and boards at the managers mess,’ placing him ‘in a most delicate and difficult position’ when it came time to deliver sanctions; his nearest ally was some 800 miles of rough sea away–and he had no boat. ## 16 May 2012 ### Dynamic Content with RStudio, Markdown, and Marked. As Markus Gesmann recently pointed out, the new version of RStudio (0.96) has some really nice features for creating dynamic reports with Yihui Xie’s knitr. You can integrate not just R and LaTeX, but also R and Markdown (as well as some other formats). If you haven’t used Markdown before, it’s basically a really simplified syntax for writing web content, though it can easily be converted not just to HTML but also LaTeX and other formats with Pandoc. See this post by Yihui Xie for a discussion of how to make HTML presentations with knitr and Pandoc. These programs make it much easier to create HTML presentations that display interactive R output from packages like googleVis (like I did in an earlier post). I’ve been using RStudio’s new features in the preview version for a few weeks and it has been really great. It has made creating web content much easier. I’ve even decided to pretty much move my entire introductory data analysis course to the web because I can create lecture notes and assignments with nice syntax highlighting and R output integration (especially interactive output). I remember a few years ago saying to my PhD supervisor that I thought it would someday be standard for theses to be written in HTML. Maybe I need to revise that slightly: theses may be displayed in HTML, but written in Markdown or (more specifically) MultiMarkdown (which has footnote and BibTeX integration). ## Recommendation A small program I really recommend purchasing if you are using RStudio with Markdown is Marked. RStudio has a Markdown previewer, but its capabilities are a bit limited. Marked gives you nicer previews with multiple styles to choose from, word counts, hyperlink validation, and some other stuff that definitely justifies its$3.99 price.

To use Marked with RStudio just drag the .Rnw or .md file you're working on in RStudio on top of the Marked icon. It will update any time you save or compile the files.

(Oh, note I think Marked is Mac only. Also, I have no affiliation with RStudio or Marked, I just really like them.)