The RWordPress package allows one to publish blog posts from R to WordPress (but please note that this package has not been updated for many years, which is not a good sign). A blog post is essentially an HTML fragment, and knitr can create such a fragment from R Markdown with the markdown package. Below is how to do this with the function knit2wp() in knitr:
if (!require('RWordPress')) {
remotes::install_github(c("duncantl/XMLRPC", "duncantl/RWordPress"))
}
library(RWordPress)
options(WordpressLogin = c(user = 'password'),
WordpressURL = 'https://user.wordpress.com/xmlrpc.php')
library(knitr)
knit2wp('yourfile.Rmd', title = 'Your post title')
Basically you set your login name and password as well as the url of the WordPress server (path to xmlrpc.php), so that RWordPress can send the post to the server. If you are a WordPress.com user, you may want to use the shortcode option, i.e. knit2wp(..., shortcode = TRUE). See ?knit2wp for details.
How to upload images? There are a few possibilities. One is to upload images to Imgur, and another is to save images to your Dropbox folder, e.g.
opts_knit$set(base.url = 'https://dl.dropbox.com/u/15335397/wp/',
base.dir = 'path/to/Dropbox/Public/wp/')
I created a folder named wp under the Public folder, and the above code tells knitr to add a prefix to the image URL’s, and generate images in the Dropbox folder. To get the URL of a file in the Public folder, just right-click on it and copy the link from the menu.
Note you can write and preview the draft in RStudio until you are comfortable to publish it. Once it is published, it is not straightforward to modify it (although you can), and that is why you, as a cool hacker, should blog with Jekyll instead of WordPress. It is always easy to deal with plain text files. Once you have got PHP, MySQL, password, plugins, … things get complicated quickly.
If you have your own server, I recommend you not to use the shortcode option, and you should consider much nicer alternative options for syntax highlighting such as highlight.js, e.g. you can add this to your WordPress template:
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/default.min.css">
<script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<script src="http://yandex.st/highlightjs/7.3/languages/r.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
I thank William K. Morris for his early experiment with knitr and WordPress. The knit2wp() function was based on his blog post. I also tested it here.
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:xie@yihui.name -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
xie@yihui.name. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).