Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rstudio Keyboard Shortcut Inline Code

Is there a keyboard shortcut in Rstudio to insert inline R code in RMarkDown documents?

ctr + alt + i is inserting a new code chunk. Similiar to that, it would be nice to have a keyboard shortcut to insert r (inline R code).
I checked Tools/Modify Keyboard Shortcuts in Rstudio but I can't find any helpful command there.

Also, browsing cheatsheets and documentations didn't help me either.

like image 318
maxpe Avatar asked Dec 24 '22 20:12

maxpe


1 Answers

One solution could be defining a code snippet.

  1. Choose Global Options from Tools Menu.
  2. Jump to the Code section.
  3. Under the Editing Tab look for Snippets and click Edit Snippets
  4. Choose Markdown. It will display existing snippets. At the end define your own snippet as shown in the image below:

Code Snippet
5. Click Save and you are done.

Typing inr followed by Shift+tab should insert the inline r code snippet.

Note: I could not control the cursor position for some reason, It would be ideal to position cursor before the last back tick.

Another solution could be writing a small Addin. See this RStudio Addins for more info

like image 199
Imran Ali Avatar answered Jan 31 '23 09:01

Imran Ali