Site icon R-bloggers

splitChunk – RStudio addin for splitting code chunks in R Markdown

[This article was first published on R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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

 

Go To: Browse Addins

 

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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.