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
-
- 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
The post splitChunk – RStudio addin for splitting code chunks in R Markdown was first shown
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.