4
votes

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.

3

3 Answers

4
votes

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

4
votes

This is probably no longer helpful to the OP, but since I was searching for the same solution and didn't quite find it in the remedy package posted above, figured I'd share the snippet that finally worked for me:

`r `r \`${1:text}`

Key was to include the syntax to be printed within inline r code. Needed to additionally escape a backtick before the text argument, which I don't fully understand, but that is what worked.

2
votes

There actually is a packaged addin on github specifically for this use case.

install.packages("devtools")
devtools::install_github("ThinkR-open/remedy")

# if you want to have the package update the hotkey settings
remedy::set_hotkeys 

https://github.com/ThinkR-open/remedy