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.
I think the flow will be something like:
- Create the post in an
.Rmdfile locally in emacs.
knitrwith my local version of R to process the
Rmdinto 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).
Upload (or copy/paste) the
HTMLsource 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).
Here is an example:
x <- seq(1, 1000) y <- rnorm(length(x)) plot(x, y)
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)