Including R Code in a Blog Post

[This article was first published on Jeromy Anglim's Blog: Psychology and Statistics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This post discusses ways of including formatted code in a blog post.

I often write posts that include computer code. This might be R code, SPSS syntax, an Inquisit script, or a Visual Basic Macro.

The Problem:
Initially I did not know how to include this code in a neat form in my posts. The layout was ugly. The font was ugly. And even worse, certain special characters such as the greater than symbol caused particular problems and would sometimes crash my blog.

The Solution:
I still don’t feel like I’ve found the perfect solution, but I now use the following procedure:

  1. Take the code and use Greg Houston‘s web script to generate the HTML
  2. Press Edit HTML in Blogger in the post; use control + F to find the insertion point; paste the HTML from step 1. 

Additional Material:

To leave a comment for the author, please follow the link and comment on their blog: Jeromy Anglim's Blog: Psychology and Statistics.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)