How to publish from R Markdown to WordPress

R Markdown is a fantastic tool if you want to present a clean piece of code. It is very useful for any data scientist that wishes to share their work. Should you have a website that is running on WordPress, you can easily publish your R Markdown as a new post straight from RStudio itself. In this article, we will be showcasing you how you can achieve this task easily.


Preparing the required libraries/packages

First, you need the following packages installed onto your WordPress: knitrdevtoolsRWordPress

if (!require('knitr')){
if (!require('devtools')) {
if (!require('RWordPress')) {


Posting your R Markdown to your WordPress Site

Once you have the packages ready you can go ahead and load them.



WordPress will be using the XMLRPC transfer protocol. On the newer versions of WordPress, this feature is automatically activated. If you use plugins that disable it, you will need to deactivate it or at least whitelist your IP address. If you’re running an older version of WordPress, you will need to activate the remote publishing located at Settings > Writing > Tick enable remote publishing.

Should you need to do that, if you are now in the directory where your blog post is located, you can go ahead and set it using the command below


#optional path to working directory

Once you are done writing and editing your R markdown, you can go ahead and post it to your WordPress. Replace the ‘wordpress_login’ with your username, the ‘password’ with the password you use for that username, the “” with the URL of your website.

Finally, replace ‘post_to_upload’ with the name of the file you wish to publish. Then add the title of your publication. Note that I set the publish option to FALSE so I can publish it as a draft in order to add the finishing touch in the WordPress editor.

#optional path to working directory
## processing file: post.Rmd
## output file:
## [1] "4207"
## attr(,"class")
## [1] "WordpressPostId"

We are all done. Your article is now on WordPress. You can easily add to the last edits before publishing it. If you have used that before, go ahead and share your experience with us in the comment section down below. If you have not, feel free to ask for help.


Leave a Comment