Publishing to WordPress with RStudio

Note: I have no idea what I'm talking about, but it's working, so here we go!

Update July 24, 2020: I changed the XMLRPC library to one that supports httr and added some additional notes at the bottom.

This is an R Markdown document I created using RStudio, an open source IDE for working with R.

One of our clients uses R Markdown as part of their workflow for creating and publishing rich reports with charts and data in HTML. For a while they've been working with the ever so available tools: copy and paste. This seems to work well for the most part, but the images generated as part of the document are included inline and the WordPress editor removes some of that image data during the process of saving after pasting. (I'm pretty sure this is something that used to work, but I haven't gone back and verified yet.)

Our client found a great blog post explaining how to post from R Markdown to WordPress and asked us if that was an option with their site. While I generally have a knee-jerk reaction to publishing with XML-RPC, I don't really have a reason why it shouldn't work. So I checked it out!

Here's the quick version:

  1. Download and install the R binary from one of the many CRAN mirrors.
  2. Download and install RStudio.
  3. Open RStudio.
  4. Create a new R Markdown file.

From what I can tell, there are three important panes in the RStudio window.

  • The file pane used to edit the R Markdown document.
  • The Console pane used to issue commands in R syntax to manipulate the document and its configuration.
  • The Help/Viewer pane on the right displays help information or a preview of the document upon request.

The file pane has an “Knit” menu that provides options for publishing the document to HTML, PDF, or a Word document. Additional configuration is required to “knit” to WordPress.

In the console, I typed these commands:

install.packages( "knitr" )
install.packages( "devtools" )
devtools::install_github(c("josephguillaume/XMLRPC","duncantl/RWordPress"))

This installs the packages required to publish over XML-RPC with commands that WordPress understands.

The josephguillaume/XMLRPC package is a fork of the duncantl/XMLRPC package and uses httr instead of RCurl to make HTTP requests. I believe this is an improvement, though I'm not familiar with the differences.

Once those are setup, an XML-RPC configuration needs to be set. Note the lowercase P in each command.

options(WordpressURL = c("https://yourdomain.com/xmlrpc.php"))
options(WordpressLogin = c( "username" = "password" ))

One minor word of caution: when I find myself publishing via XML-RPC or anything else that requires a plaintext username and password, I add separate user account to my site with a lower set of capabilities and then manually adjust the author information once the post is properly published.

Now we're ready to publish. The RWordPress package provides the knit2wp command. If you type ?knit2wp in the console pane, information appears in the help pane explaining how to manipulate the command to create a new post, edit a post, and assign categories and tags.

To publish this post as a draft on my site, I used:

knit2wp('testpost.Rmd', title='Publishing to WordPress with RStudio', publish = FALSE )

After I published the first version and made some changes, I used the following to edit the post:

knit2wp('testpost.Rmd', title='Publishing to WordPress with RStudio', action=c("editPost"), postid = 13616, publish = FALSE )

And here we are. This is pretty cool!

Caveats

Data URI Images and unfiltered HTML

Note that images generated through RStudio (maybe RMarkdown in general?) are added to content as Data URIs and will not be uploaded to the WordPress media library. This also poses an issue if the user publishing a content is not allowed to push unfiltered HTML. WordPress will strip that data URI as a security precaution when the post content is saved. On single site WordPress, you'll need to be at least an Editor. On multisite WordPress, you'll need to be super administrator.

Ongoing use

If you're familiar with R, this may be obvious, but it wasn't to me! When you start RStudio again after exiting, you can use the library() command to reload required packages:

library('knitr')
library('devtools')
library('RWordPress')
library('XMLRPC')
options(WordpressURL = c("https://yourdomain.com/xmlrpc.php"))
options(WordpressLogin = c( "username" = "password" ))

I'm sure there's a way to maintain a persistent state, but I haven't looked. 🙂

Why R Markdown?

I'm done with the overview, but I'm including this section as an example. The framework for it was provided by RStudio when I first created the document.

From what I can tell, the cars variable is already provided as a dataset. When I type cars in the console pane, I get a list of numbers populating speed and distance columns. If I type summary(cars) in the console, I see the a version of the table listed below, which this markdown document says to embed:

##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

And I can plot that same data into a graph with plot(cars):

plot of chunk Cars plotted

How cool!

Thoughts for the week’s end

Last Friday’s NYT crossword hit me like a sack of bricks. Looking back, I only spent 12 minutes on it before bailing, but it felt like an eternity and I got nowhere.

That feeling bled into Saturday and I didn’t even open the puzzle, I just spent more time reading instead. I finally got back into the groove on Sunday, which has become reliably solvable as long as I set aside the time.

At some point before solving Sunday’s I decided I had had enough of Thursday, Friday, Saturday and would just do old Monday, Tuesday, Wednesday puzzles in their place. But here I am, back on a 7 day streak and everything seems possible again.

Also, going back to 10 year old Monday puzzles is not that easy! It’s like playing old editions of Trivial Pursuit and trying to remember various geopolitical changes over the last 30 years.


We watched the Aaron Paul episode of Open Door on Hulu last week mostly because I thought that I always have fun watching other people show off their houses. Either the vibe of the show was way off, or I just don’t really enjoy the flaunting of extreme wealth anymore. Anyhow, that’s not the point.

Toward the end of the episode—we fast-forwarded pretty heavily—there’s a brief shot of them loading some dishes into a dishwasher. It hit me that no matter how great your kitchen is or how rich and famous you are, the dishwasher is still a dishwasher.

Then a few days later, up pops a headline about how Halsey fractured her ankle while loading the dishwasher. See!


I saw the Zeros and they looked like me
This is the America that I want to be
Anarchy and Hollywood, the land of the free
I saw the Zeros and they looked like me

Alejandro Escovedo, Sonic USA

I listened to a lot more Escovedo this week after gushing so much last week. I went through his 2018 album, The Crossing, a few times and the lyrics in Sonic USA made me go hunting.

The Zeros were a punk band in the mid-late 70s fronted by Javier Escovedo, Alejandro’s younger brother. I enjoyed this LA Weekly piece from 1999 on the band as a guide to how heavy of an inspiration various music can have on people.


And we don’t take requests
We won’t shut up and sing
Tell the truth enough
You’ll find it rhymes with everything

Jason Isbell and the 400 Unit, Be Afraid

I listened to Reunions again this week and looked up the line above only to find out I had already done so back in February. This was funny to me because I looked up the lyrics to Elton John’s Levon last night after an exchange with Rich on Twitter only to find I had already done so back in January.

Lyrics, they’re great!


“I dislike Man City because it is Oasis’s club. Noel Gallagher is the most overrated songwriter in the whole history of pop music. They were perfect for the Brit press because they behaved badly and got all the attention. Blur were really great. That guy Damon Albarn is a real fuckin’ songwriter.”

Steve Earle, on being an Arsenal fan

I know maybe 2 people that will enjoy this quote. I love it. 😂

I agree with the Damon Albarn part; I’m not invested in Man City vs Arsenal; and while I might at one point have thought Oasis is a bit overrated, I’ve generally stopped carrying opinions like that around. I do like Steve Earle.


I’ve been grabbing more and more albums through Bandcamp and listening to them via the Sonos app rather than through Spotify. The quality is often noticeably better and playing music that you’ve paid an artist for just feels better. How strange to be back at this point after so many years of streaming!


My spam detection rate is still at 99.6% after almost 1000 spam comments. I think my next task for Self Sustaining Spam Stopper is to assume that anything caught with the honeypots is spam and can just be deleted.


The last week has been yet another heartbreaking week.

The murder of George Floyd over twenty dollars added fuel to a righteous anger in people all over the country and there are now protests in every major city and many small towns. Police, in what has become a standard approach in the US, have reacted with violence and made a sad situation worse.

In times like this I default to trying to read everything and find some sense of understanding. I’m not always sure of what to say. For the moment, it’s helping to find pieces written by others that align with how I feel. I need to sort out what active steps I can take next.

After reading through Jake’s recently updated post on using thermodynamics to explain why riots and stampedes occur—he uses the equation provided by Gibbs free energy, I’ve been thinking through how this applies to the protests in an age of militarized police forces.

My take: The military gear worn by police when responding increases the stress of a situation. The task as commanded of the police—wear this riot gear and contain the protest—reduces the amount of empathy they can afford to have for protestors. The change in energy is drastic. What would we expect other than chaos?

The Marshall Project is a “nonprofit news organization that seeks to create and sustain a sense of national urgency about the U.S. criminal justice system.” Their site has plenty of curated material on a variety of topics, including police abolition. I reached Matt Taibbi’s article from 2014, “The Police in America are Becoming Illegitimate”, through that page and I’ve started to think through what a future without policing could look like.

I also connected with Paul Butler’s opinion piece from Saturday in The Guardian, “Policing in the US is not about enforcing law. It’s about enforcing white supremacy”.

We can’t expect things to get better without making drastic changes. We can’t expect groups with systemic power to forfeit that power voluntarily.

Black lives matter. ❤️

Thoughts for the week’s end

And it stoned me to my soul
Stoned me just like Jelly Roll
And it stoned me
And it stoned me to my soul
Stoned me just like going home
And it stoned me

– Van Morrison, And it Stoned Me

A three week break that seemed like two. Sounds about right.

Hello from the other side.


The line “and it stoned me” popped into my head the other day while I was in the midst of hunting memories due to a random song that popped out of somewhere which is how it always happens.

I listened to Alejandro Escovedo’s A Man Under the Influence a few times this week for the first time in quite a while. It’s one of those albums I can still associate a specific time and feeling with. There are a handful of albums from the early 2000s that probably fit in that way. One thing that was nice about pre-internet-everywhere was cars with CD players and the same disc on repeat for weeks at a time. 🙂

Anyhow. The entire album is great and I have good memories of several tracks. The other night I was specifically thinking of seeing Escovedo perform Velvet Guitar at the Metro in Chicago as part of benefit show for Neon Street, which I believe is or was a teen homeless shelter. The First Waltz was modeled after The Band’s The Last Waltz and gathered a bunch of excellent performers together for a few years.

It was at these shows that I learned of Alejandro Escovedo and watching him perform stoned me.

I even told Michelle the other night that watching him play that one song—Velvet Guitar— had permanently altered my relationship with music.

But there’s a problem! I don’t know what to trust or believe!

He was one of the few musicians that played at all 3 benefit shows over the years and I saw each of these performances:

  • March 25, 1999: Pissed off at 2am
  • March 22, 2001: I Wanna Be Your Dog
  • March 23, 2002: Velvet Guitar

So. I know Velvet Guitar impacted me, and I stand by most of the memory. But does my brain now mix that performance with the earlier ones? There’s no way I wouldn’t have fallen in love with him after seeing I Wanna Be Your Dog so I’m guessing I was already at least a passive fan by 2002.

I’m going to accept the ambiguity and, unless otherwise corrected, continue to remember that it was the Velvet Guitar performance that did the most.


It’s amazing how indelible a memory seems until you start to source it.

I’ll leave it at something like: sourcing may change memories, but it gives them a little more dimension.

Example: I had completely forgotten that Steve Earle played the 2002 show!

And bonus: We saw Iggy Pop perform I Wanna Be Your Dog at the Vic only a couple months later in 2001.

My actually indelible memory from that show is being absolutely convinced my ear drums were going to explode. Thanks, Iggy.


While digging through Escovedo’s catalog on Spotify, I ended up on the No Depression: What it Sounds Like, Vol 1 comp album. I enjoyed the listen, so I searched for No Depression to see if they had other volumes or playlists. I then ran into their Spotify playlist of favorite tracks for the month. The first track this month is Chuck Mead’s I Ain’t Been Nowhere, a great re-purposing of I’ve Been Everywhere.

And from all of that I finally ended up on the No Depression website, saw they were a quarterly nonprofit roots music journal, enjoyed what I was looking at, and subscribed.


No Depression’s site also reminded me that the new Steve Earle album, Ghosts of West Virginia, was due this week. It’s such a great surprise to forget that something is coming and then relearn about it the day before.

I fired it up Friday morning and it was good!

Other things that have been on repeat lately: Fiona Apple’s Fetch the Bolt Cutters is really, really good and I very much enjoy Jason Isbell’s Reunions.


I’ve been tinkering with my own plugin to stop spam comments, named as well as I can name things, and spent a bit of time over the last many months trying to dial in a handful of word lists as a way to stop most of the spam without relying on an external service.

It’s a game of whack-a-mole, really. You identify a handful of words or patterns that seem to do the trick against a handful of comments just in time for a new bot with new patterns to slide on through and leave a bunch more. Repeat.

A couple weeks ago, after letting the spam pile up a bit, I determined that this strategy was boring and annoying and was about opposite the amount of effort I really want to put into spam detection.

Instead, I added a couple of hidden honeypot inputs: one contains a string that should not change; the other a value that is cleared by JavaScript 1.5 seconds after page load. If either of these appear incorrectly, or if neither appear, the comment is classified as spam.

At about 3 weeks, I’m at a 99.7% spam detection rate. Simple success!


While doing some light pandemic reading, I noticed the words “viral titer” for the first time. I went a googling and landed on titer’s Wikipedia page.

Titer is concentration. Viral titer is the concentration of virus required to infect cells. Titer is also the temperature at which a fat solidifies. The Wikipedia entry adds: “The higher the titer, the harder the fat”.

The phrasing made me laugh and I hope the cleverness of the phrasing was intentional.


Now that I’ve spent this much time thinking about titer, it better appear in a crossword.


I think I’ve learned that schedule is important for me if I want to write regularly. Skipping the Thursday night session the one week was a disruptor. We’ll see what happens next week!

It’s Memorial Day weekend in the US, so this late Saturday posting is more like a Friday posting, which technically means I hit my deadline by my rules.

May it get sunny for a few days and may everyone find music that alters them. 🎸🍻

Thoughts for the week’s end

Hey, it’s not Friday. Happy Saturday?

This is the first time I’ve missed my normal Thursday night writing and editing session, but I also kind of like doing this over coffee on Saturday.

We’ll see.


Way, way back when, in the long distant 2000s, I spent many years doing tech support via phone and email for a wide variety of clients in an outsource call center. I started at the beginning of the 56k modem explosion and spent countless hours over the years participating in the progression of getting people connected.

Dial-up, ISDN, DSL, cable, a little bit of fiber. It’s amazing how quickly things moved when you look back. There was probably only a 5 year (less?) span in which we went from troubleshooting AT commands in a terminal window in Windows 98, trying to figure out why that V.90 bong sound was eluding us, to having customers go computer to computer throughout their house while troubleshooting their new wireless router.

Don’t ever get me started on printers.


The key to walking a novice user through something like typing terminal commands was often to not give any hint to how “technical” it was. Move the mouse here, click here, type this, click OK, type this, read me what you see. However uncommon many issues might seem, they were often resolved with one of only a few series of repeatable steps.


We once provided support for a new to the market, very low-cost desktop computer. It was something like $299 at Sam’s Club, maybe even less. Early support calls suggested that something was seriously wrong—many computers just weren’t working. I left in the middle of the night from the Chicago area to arrive in St. Louis as Sam’s Club opened. We had no actual reference computer yet and that was the nearest location one was available.

I walked in, grabbed a couple computers, paid, and drove 4 hours straight back to work. It was a great day.

It didn’t take long to determine something was wrong in the way the processor was seated on the motherboard. All we really had to do is take it out, put it back in, and things Just Worked.

A few calls later, we had a repeatable process, and then it became almost a competition. How quickly could you walk someone who has never seen the inside of a computer through removing the case, re-seating the processor, and putting everything back together again?

If I remember right, we made it into the sub-10 minute range, which at least impressed me.


I started this all for a reason and now I’m stuck reminiscing.


I had a video chat over Zoom this week with someone 14 time zones away. Everything about the call was smooth. There was no noticeable audio or video lag, the quality was excellent, and the conversation was as natural as video conversations can be. As soon as we disconnected I sat for a second realizing how amazing it all was.

One of our clients in the early 2000s was working on their version of a video IP phone and I spent a bunch of time messing with it to try and find various problems so that we had a chance at supporting the thing. The setup process was so manual and fragile and while video technically worked, the experience was a whole lot of “well maybe this will be decent next decade”.

And here we are. Bandwidth solves all?


I wonder what it would be like if voice and video over IP had worked out in a way where we actually did have desk phones with video screens rather than webcams and cell phones that handle it all for us.

Was it the introduction of the iPhone or Blackberry that changed everyone’s expectations around how mobile all of our communications should be?


I listened to Gish for the first time in a long time this week and love how much it holds up. It’s definitely a nostalgia influenced decision, but I added I Am One to the best first bars on first songs on first albums playlist.

I then listened to Siamese Dream and had great flashbacks of practicing guitar to that album over and over and over and over and over. What did my roommates even think?

I’m also not sure what I would have thought if someone told me in the late 90s that my obsessive interest in the music of Billy Corgan would transfer to pretty much every other musical thing except that. 😂


At first glance—I listened to one song and skimmed through others—Post Malone’s Nirvana tribute is everything a Nirvana tribute should be. One of my favorite things is seeing how talented musicians are outside of their usual rehearsed playlists and environments.


The screen has replaced the window in the side door, so the weather has officially been determined nice.

Enjoy the weekend. 🍻