<p>There is another option that has not been pointed out here.  You can insert an HTML comment that will automatically turn on syntax highlighting within a post (see: <a href="https://meta.stackexchange.com/q/184108/187282">What is syntax highlighting and how does it work?</a>).  The way it works is that you put <code>&lt;!-- language: lang-r --&gt;</code> on its own line prior to the code.  Then the next code block will be highlighted as R code.  (Note that the comment itself will not be visible in the post.)  </p>

<p>This can be done with a number of languages, including (at least), <code>lang-r</code>, <code>lang-python</code>, and <code>lang-matlab</code>, as well as the major programming languages (<code>c++</code>, <code>java</code>, etc.).  I don't know if there is support for other statistical software languages (e.g., <code>SAS</code> or <code>Stata</code>).  </p>

<p>There are a couple of limitations with this.  First, there will only be highlighting within code <em>blocks</em>; inline code is not highlighted.  Second, this will only highlight the <em>next</em> code block, if there is text, or a figure, or something else between one code block and a subsequent code block, the subsequent code block will not be highlighted.  Thus, you need to either add the comment prior to each code block, or use <code>&lt;!-- language-all: lang-r --&gt;</code> to highlight all subsequent code blocks (note the addition of <code>-all</code> in the comment).  Third, these comments will not highlight code blocks prior to the comment.  Lastly, the comment will only highlight the code blocks within that post (question or individual answer); other posts on the same thread will not be affected.  (Adding, say, the <a href="https://stats.stackexchange.com/questions/tagged/r" class="post-tag" title="show questions tagged &#39;r&#39;" rel="tag">r</a> tag to the question will highlight all code blocks on the thread.)  </p>

<p>You can also use these comments to locally override syntax highlighting on a thread.  For example, if a question included the <a href="https://stats.stackexchange.com/questions/tagged/r" class="post-tag" title="show questions tagged &#39;r&#39;" rel="tag">r</a> tag, but a code block in an answer was not r code, highlighting could be turned off via <code>&lt;!-- language: lang-none --&gt;</code>, or could be switched to highlighting for a different language, e.g., <code>&lt;!-- language: lang-python --&gt;</code>.  </p>

<hr>

<p>The following provides an example of how this can be done.  Because the HTML comments will not show up, when I place them, I will subsequently place a copy of the comment as inline code to make it clear what was done.  (Hmmm, annoyingly the syntax highlighting does not seem to be working on meta, although I just tested it and everything below shows up as it should on the main site.)</p>

<p>Here is some text answering a question.  </p>

<pre><code>here  # is some non-highlighted code in a code block
</code></pre>

<p>Now I have more pearls of wisdom.  </p>

<p><code>&lt;!-- language: lang-r --&gt;</code> </p>

  

<pre><code>this = "some highlighted code"  # nifty!
</code></pre>

<p>Random crankiness and weird digressions from old man.  </p>

<pre><code># once again, code is not highlighted
</code></pre>

<p>Sage remarks.  </p>

<p><code>&lt;!-- language-all: lang-r --&gt;</code> </p>

  

<pre><code>highlighted  # code
</code></pre>

<p>Increasingly tedious exposition with every other word inexplicably italicized.  </p>

<pre><code>code "still"  # highlighted 
</code></pre>
