Keyboard shortcut for addin in dcf file

ide
addins

#1

Is it possible to define in the addin dcf file the keyboard shortcut to associate with the addin?

I can manipulate the json in the ~/.R/rstudio/keybindings/addins.json, but there is no way in the console to invoke the change in the IDE.

Is there a solution that I am missing? If not could you open a field in the dcf for rstudio to read (onLoad | onAttach) of a package?


#2

You can, but I believe you’ll have to restart the IDE for any changes to keybindings done in this way to take effect. There’s no user-accessible way (beyond the Modify Keyboard Shortcuts dialog) to refresh the set of loaded user keybindings at the moment.


#3

I can what? update the json and restart the IDE? is there a hotkey for the keyboard shortcut update button?


#4

Right; updating the JSON and restarting the IDE should pick up the new keybindings. There’s no hotkey for this, unfortunately.


#5

small follow up. we added a script in the remedy package to have hotkeys be added by script to the IDE.


#6

@kevinushey, @jonathan i wrote a package to overcome this issue and uploaded it to CRAN, but got an email that CRAN cant allow a package that writes to disk other than tempdir.

Dear Jonathan Sidi,

your package creates ~/.R/rstudio/keybindings:

$ grep -r 'rstudio.*keybindings' .
./rsam/R/rm_shorcut.R: path="~/.R/rstudio/keybindings/addins.json",
./rsam/R/set_shortcut.R: path="~/.R/rstudio/keybindings/addins.json",
./rsam/R/fetch_keys.R:  json_now <- jsonlite::fromJSON("~/.R/rstudio/keybindings/addins.json")
./rsam/R/zzz.R:  key_dir <- '~/.R/rstudio/keybindings'
./rsam/R/zzz.R:    dir.create('~/.R/rstudio/keybindings',showWarnings = FALSE,recursive = TRUE)
./rsam/R/zzz.R:  key_dir <- '~/.R/rstudio/keybindings'
./rsam/R/zzz.R:    dir.create('~/.R/rstudio/keybindings',showWarnings = FALSE,recursive = TRUE)


Please do not create directories/documents outside of tempdir(). This is not allowed by CRAN policies.

Please fix this immediately and resubmit a new version with increased version number via the CRAN web form.

Best,
CRAN

can this issue be solved in the IDE dev?


#7

CRAN typically allows users to do this in interactive processes. From the CRAN Repository Policy:

Packages should not write in the user’s home filespace (including clipboards), nor anywhere else on the file system apart from the R session’s temporary directory (or during installation in the location pointed to by TMPDIR: and such usage should be cleaned up). Installing into the system’s R installation (e.g., scripts to its bin directory) is not allowed.

Limited exceptions may be allowed in interactive sessions if the package obtains confirmation from the user.

Can you wrap the associated code in an interactive() check + prompt the user beforehand?