splitChunk – RStudio addin for splitting code chunks in R Markdown

February 22, 2017

(This article was first published on R, and kindly contributed to R-bloggers)

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.


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



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

Go To: Browse Addins


Add shortcut

Add shortcut

The post splitChunk – RStudio addin for splitting code chunks in R Markdown was first shown

To leave a comment for the author, please follow the link and comment on their blog: R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)