title: What command converts knitr R Markdown into Stack-Exchange-friendly Markdown?
body: <p><strong>Motivation</strong>:
  I often want to paste the results of a quick analysis using R Markdown into a StackExchange site. This includes the <a href="https://stackoverflow.com/questions/tagged/r">R-tag on Stack Overflow</a>, <a href="https://stats.stackexchange.com/">Cross Validated</a>, or even a domain specific analysis on sites like <a href="https://cogsci.stackexchange.com/">Cognitive Sciences Stack Exchange</a> (e.g., this quick analysis of <a href="https://cogsci.stackexchange.com/questions/922/what-is-the-correlation-between-objective-indexes-and-aggregated-self-report-mea/1067#1067">OECD life index data</a>).</p>
  
  <p><strong>Problems with default conversion:</strong>
  The <strong>default</strong> markdown output of <code>knitr</code> is not suitable for inclusion on StackExchange.
  The main problems I can see are that</p>
  
  <ul>
  <li>images are referenced to the local hard drive</li>
  <li>code chunks are not tab or space indented; rather they use github style Markdown (i.e., no indentation)</li>
  </ul>
  
  <p>I.e., the chunks look like this:</p>
  
  <pre><code>```r
  some code
  ```
  </code></pre>
  
  <p>and output looks like this</p>
  
  <pre><code>```
  ## some output
  ## ...
  ```
  </code></pre>
  
  <p>There might also be other specific issues to consider, such as </p>
  
  <ul>
  <li>ensuring tables are included properly</li>
  <li>ensuring that equations are passed correctly for sites that support MathJax like Cross Validated and Cognitive Science Stack Exchange.</li>
  </ul>
  
  <h3>Question</h3>
  
  <p><strong>What is a good command for converting R Markdown into Markdown (or HTML) suitable for simple inclusion into Stack Exchange sites?</strong></p>
  
  <p>I think an ideal command would be a one-liner that takes an R Markdown file and generates a file where the entire content can be pasted directly into Stack Exchange to yield a well-formatted question or answer.</p>
  
  <p>I share <a href="https://github.com/downloads/jeromyanglim/assorted-files/non-sig-r.rmd" rel="nofollow noreferrer">this simple rmd file</a> with a couple of code chunks, a figure, and an equation as a test example.</p>
  
  <p><strong>Initial thoughts</strong>:
  Hosting of images on imgur would presumably sort out the issue with images. This can be done by including the following in the R Markdown file, but it would probably be simpler if this instruction was incorporated into some one-liner command.</p>
  
  <pre><code>``` {r }
  opts_knit$set(upload.fun = imgur_upload) 
  ````
  </code></pre>
  
  <p>It might be worth considering whether HTML or Markdown is the better format for pasting into  StackExchange. The <code>markdown</code> package provides a lot of flexibility.</p>