Post to Wordpress from RMarkdown

RMarkdown is the lingua franca of my world. There are tons of times that I want to post something from my markdown work on my blog (either personal or work) and for that there are many options. I could make it into a PDF and embed it, I can copy-paste and put it in normal wordpress docs or I can have R do it for me. Guess which one I am going to use…

Preliminaries

First, you need to get your document done. It typcially make a html document and get it where I like it. Then you need to do the following.

<code class="r"># make sure you have these installed (only once)
install.packages("devtools")
devtools::install_github("duncantl/RWordPress")
</code>


Once you have thos you can (outside the document) execute the foloowing. First, load in the library

<code class="r">library(RWordPress)
</code>


Then set some options. These are case sensitive. The login one uses your name as the key and your wordpress password in quotes. The URL must have the xmlrpc.php on the end.

<code class="r">options(WordpressLogin = c(rodney = "your_password"),
WordpressURL = "https://rodneydyer.com/xmlrpc.php")
</code>


Then we post the file up.

<code class="r">library(knitr)
categories <- c("R","Software","WP")
knit2wp( 'Markdown2Wordpress.Rmd',
title="How to post to wordpress from RMarkdown",
publish=FALSE,
categories = categories)
</code>


I’ve wrapped this up in a function that I pass the RMD file name, title, and categories to and it works perfect.

Including more complicated stuff like

You can also embed plots.

<code class="r">par(mar = c(0, 1, 0, 1))
pie(
c(280, 60, 20),
c('Sky', 'Sunny side of pyramid', 'Shady side of pyramid'),
col = c('#0292D8', '#F7EA39', '#C4B632'),
init.angle = -50, border = NA
)
</code>


and equations

[ A = (\pi * \lambda \times r^{4}) / \alpha ]

though I do not think that DT::datatables work

<code class="r">library(DT)
datatable(mtcars, rownames = FALSE, filter="top", options = list(pageLength = 5, scrollX=T) )
</code>

## PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.

## Warning in normalizePath(f2): path[1]="webshot8f05339c3c76.png": No such
## file or directory

## Warning in file(con, "rb"): cannot open file 'webshot8f05339c3c76.png': No
## such file or directory

## Error in file(con, "rb"): cannot open the connection

Father, Husband, Brewer, Professor

Middle aged guy trying to keep it all together and figure out how to best navigate the world as it is. Technology geek, practitioner of fermentation sciences, researcher, biologist.