Tag Archives: markdown

Using Rmarkdown with knitr to compose Wordpress posts

What I’d like to be able to do is use knitr on an R markdown (i.e. .Rmd) document so include text, code, code output, and images to make a nice looking WordPress post that I can compose and edit locally. And advantage to this is that I can use whatever editor I want for doing the composing (like Aquamacs), and that everything is contained in a single source document.

Workflow

I think the flow will be something like:

  1. Create the post in an .Rmd file locally in emacs.

  2. Use knitr with my local version of R to process the Rmd into either a proper md (Markdown) or an HTML that I can just upload (NOTE: the HTML option doesn’t really seem to work … will maybe need to look into this some more).

  3. Upload (or copy/paste) the md or HTML source into WordPress. The big question is what will happen with generated images, etc. With Markdown, I think the images are created in a directory that is dynamically linked to, but for the HTML there is maybe some way that images are embedded (it appears the embedding isn’t compatible with copying and pasting the HTML source produced by knitr — I guess the images will have to be uploaded manually).

Some code

Here is an example:

x <- seq(1, 1000)
y <- rnorm(length(x))
plot(x, y)

plot of chunk unnamed-chunk-1

Post script

Copying and pasting the .md source produced by knitr works pretty well, though the image links will be broken. To fix this, each image produced by knitr needs to be added to the media library, and then inserted into the post to get the proper path. E.g. for the test figure above, the path is https://codedocean.files.wordpress.com/2014/01/unnamed-chunk-1.png. The linking to the image can still be done in a “markdown” way by using something like:

![plot of chunk unnamed-chunk-1](https://codedocean.files.wordpress.com/2014/01/unnamed-chunk-1.png)
Advertisements

This is my first post using Markdown

This is my first post. I’m using Markdown to see if it will work properly.

Coding

How do I do code chunks?

x <- rnorm(1000)

Figures

What about figures that might be produced from code chunks? Can I use knitr with markdown to export a post that I can just upload into WordPress?