using R markdown on wordpress

Abstract. An explanation is given for using the vim editor to compose wordpress blog items in normal-markdown or R-markdown format.

1. The gist of R markdown format.

R markdown is an extension of normal-markdown that permits the embedding of R code and output (including figures). WordPress seems not to handle the figure-inclusion mechanism, but there is a workaround: create the figures locally then use the ‘insert media’ button on wordpress to upload and include them in the text. For more details of R-markdown format, see e.g. the rstudio documentation.

2. Setting up wordpress to accept markdown format.

As noted in a comment on this posting, go to the “Dashboard” and then select “Settings”, then select “Writing” and then click the box next to “Use markdown for posts and pages”.

3. Guidelines for vim editor.

WordPress will insert line breaks whenever they are found in the text, so it is important not to use auto-fill in Vim. This can be set up by inserting the line

autocmd! BufNewFile,BufReadPre,FileReadPre *.Rmd so ~/.vim/rmd.vim

in the ~/.vimrc file, and then creating a new file in ~/.vim named rmd.vim that contains

" wrap long lines in the editor window ...
set wrap
" ... and prevent automatic end-of-line insertion
set textwidth=0 wrapmargin=0

4. Guidelines for emacs editor.

(Something may be added here if someone tells me what to add…)

5. Converting R markdown to normal markdown

R-markdown may contain R code chunks (with the token {r} after the triple-backtick). When these are run through the knit() function provided in the knitr package, the braces are removed, which is the standard for syntax-enabled markdown as used on wordpress.

Conversion from R markdown to normal markdown can be done easily inside R, with the following (in this case for the file used for the present posting).


5 thoughts on “using R markdown on wordpress

  1. clarkrichards

    Regarding the `{r}` or `r` in the triple-backtick notation: in the `.Rmd` file you use `{r}`, which when converted to markdown through knitr removes the curly braces, producing markdown which is standard and recognized by WordPress.

    The reason for the curly braces in the `.Rmd` document is because there are a whole host of options that you can set in them (similarly to when processing an `.Rnw`). When the `.Rmd` is “knit” those options are processed, but not displayed in the `.md` file (since they are not standard markdown, and apply only to the processing or R code chunks).

  2. clarkrichards

    You should enable Markdown formatting for comments, too. From the dashboard do Settings -> Discussion and enable “Use Markdown for comments”.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s