splitChunk – RStudio addin for splitting code chunks in R Markdown

When working with R Markdown I usually use the key command cmd+alt+i to insert new code chunks, i.e. ” “`{r}\n\n“` “. Often I do multiple things in one chunk and then want to split the chunk in two and write some text in-between.

To do this I have created an addin for RStudio that inserts ” “`\n\n“`{r} “. I have set this up with the key command cmd+alt+shift+i as it is kind of a “shifted” version of inserting a new chunk.

The cursor is positioned in-between the chunks allowing me to write an introduction to the following chunk or similar.

Install

The package splitChunk can be installed from GitHub . Paste the following code into the console and run it:

install.packages("devtools")

devtools::install_github("LudvigOlsen/splitChunk")

It is also available through the addinslist package ‘s Browse RStudio Addins addin.

Add Key Command

After installing it, add a key command (e.g. mac: cmd-alt-shift-i, win: ctrl-alt-shift-i) by going to

  • Tools Addins Browse Addins Keyboard Shortcuts.
  • Find Split Code Chunk and press its field under Shortcut.
  • Press desired key command.
  • Press Apply.
  • Press Execute.
  • Press chosen key command inside a code chunk in R Markdown

Go To: Browse Addins

Add shortcut