Saturday 1 December 2018

Jumping between RStudio Notebooks and Google Blogger

I've been looking for some time for a way to prepare blogs - a mix of text, highlighted code and diagrams - in RStudio notebooks and get them easily into Blogger.

A simple cut-and-paste doesn't work (on MacOS, from Safari or Chrome). Inspecting the html, somewhere along the line the code gets stripped out, just leaving the HTML tags behind. So code blocks are empty.

The work-around I've found is only half clunky! (This is for MacOS)


  1. In RStudio, R notebooks. Get rid of "code folding" to avoid having 'hide' buttons that don't work lying around in your blog. This is best done from the 'output options' menu (next to the 'preview' button just above your code). If you insert this directly in the code, the R notebooks seems to revert to markdown. You should see something like this:

  2. Header: 

    title: "XXX"
    output:
      html_notebook:
        code_folding: none
        highlight: tango
        theme: flatly

  3. Preview - in Chrome (not Safari). 
  4. Select all - copy - paste into rtf in TextEdit.
  5. Copy again and paste into ‘compose’ pane of Blogger.
  6. Select all, set text background to white (of all) to get rid of in-line code having a black background.
  7. Delete each image. (They look ok, but will show as 'unknown png' when you preview)
  8. Drag each image from Notepad, separately, and resize. (If you want more control, then you need to export each separately from RStudio and import into Blogger.
  9. Cut out the title, and paste it into the title box of Blogger.

If you have a neater way, do let me know!



No comments:

Post a Comment