Posting an Rmd File to WordPress

There are four R packages you will need to be able to post an Rmd file to WordPress. Yes there are alternatives you can generate the HTML yourself and copy and paste things, but why would you want to do it?

The required packages:

Package Name Authors Website
1 Knitr William K. Morris, Yihui Xie, and Jared Lander
2 RWordPress Duncan Temple Lang

Install the required packages.

Ok, here is where I had to do an extra step. The Knitr and Devtools package is a normal installation from CRAN repository. However the XMLRPC and RWordPress packages need to be installed from github. The built-in function from R-Studio to install from github didn’t work. So I just copied the .zip files and changed them to .tar.gz and all was well with the world.

Code to install knitr package.

Get the RWordPress package from

If you are using Microsoft Windows you can use this link

If you are using Linux or Linux Variant you can use this link

Save the file to your local computer.

Inside of R Studio, from the tools menu, Install Packages. And from the pop up dialog box choose Install From Package Archive File
And then browse for where you stored the local file.

Alternatively you can use the R command.

Sending the Converted Rmd File to WordPress

After you have written and saved your Rmd file, you can then post it your WordPress site.

The code is mainly self-explanatory but a few notes.

  1. You need to make sure your local directory is set so that knitr can find the Rmd files.
  2. Note the spelling in the options. It is case-sensitive and it is a lowercase p in WordPress.
  3. knit2wp function from knitr is a wrapper around the functions in the RWordPress package. Use the ever useful ?knit2wp for details.
  4. The publish = FALSE option means that WordPress will not make the posting publically visible. If you set it to TRUE then the posting will be publically visible immediately. I think it is better to put to false and preview the posting first in WordPress before making it publically available.
  5. The knit2wp will send the .Rmd file over as a post by default but the action parameter does allow you to change it to a WordPress page.

Checking the Results

Now you can login to your WordPress website and check out how things look.
They should look fine, and if they do, go ahead and publish.


Let me know if you found the above useful.