Modifying RStudio Keyboard Shortcuts in .RProfile

rstudio

#1

I am wondering if there is a way to customize RStudio keyboard shortcuts (i.e., the ones you see in RStudio by default when you type Alt + Shift + k) in an .RProfile. I know you can do this manually by going to "Tools --> Modify Keyboard Shortcuts" in the IDE, but I am looking to do this automatically upon startup.

If it helps, here is an analogy. To change your choice of CRAN mirror, you can go to "Tools --> Global Options --> Packages" and change the mirror manually. However, you can also do this in a .RProfile script as follows:

local({
     r <- getOption("repos")
     r["CRAN"] <- "https://cran.rstudio.com/"
     options(repos=r)
})

I have not yet seen an online resource that addresses my question, so I thought I would ask it here. I know my choice of keyboard shortcuts would be preserved from one R session to another, but I am looking to be as efficient as possible (e.g., maybe I end up switching computers in the future - I could just run my .RProfile on a new machine with my preferred keyboard combinations instead of having to manually change them all again).


#2

In case it helps, here's the bit of documentation about how keybindings are saved:

Saving and Loading

The RStudio keybindings are saved as JSON files in the directory ~/.R/rstudio/keybindings/ — you can find the bindings for the editor and RStudio itself at:

~/.R/rstudio/keybindings/rstudio_commands.json
~/.R/rstudio/keybindings/editor_commands.json

From: