R Syntax Highlighter

Pretty RPretty R is an online tool and r syntax highlighter that transforms R source code into HTLM code for website development.  The result is easy to read R code for high quality web presentations. The Pretty R webpage is a good learning tool as it provides the HTML code details required to deliver syntax highlighting that complies with R documentation from inside-r.org.

In practice, the use of a website translator is not the most efficient way to convert R into syntax highlighted HTLM.  The brute force approach is to write HTML or CSS code directly, layering complex web syntax into the analytic code.  For me, I have enough trouble making sure the technical code works, and works efficiently, let alone doing dual-purpose development for analysis and web posting.

R syntax highlighters are reviewed below, benefiting from hands-on trial and error.

R Mardown is another approach for converting raw source code for web pages, but R Markdown requires the creation of a separate text or *.rmd document.  The text code document serves as a bridge, where R is translated into HTML using a 3rd party package and utilities to interface with your website.  Again, the requirement is to manually embed R “code chunks” for analysis into code for web translation.

Syntax Highlighter Evolved is one solution appropriate for websites built using the WordPress.org framework.  The plug-in converts R code into HTML code quickly and it easily separates analytic work from web design.  Basic usage involves dropping R code direct into the HTML text file for the website and wrapping the code as follows:


The mandatory parameter language, or lang for short, must be a supported language, like R or some other language, that requires HTML conversion. The list of supported languages and optional parameters that can be inserted into the source code tags can be found here.

Crayon Syntax Highlighter is the solution used here.  It offers more control compared to other syntax highlighters for WordPress, and the code formats can be easily customized.  I suppose its a matter of taste, but when I saw Crayon for the first time I didn’t hesitate to switch from other tools.  The presentation quality is higher and the code blocks include menu items to facilitate user interface.

Switching from Syntax Highlighter Evolved was relatively straightforward.  It required changing code tags across the website since the basic syntax for Crayon is:


I opted for a manual conversion since the Crayon code editor supports a range of code control options.  The result is that raw source code in text format is converted into HTML code presentations like this:


This entry was posted in R Programming, Website. Bookmark the permalink.