| Title: | Manage 'RStudio' Preferences and Addin Shortcuts |
|---|---|
| Description: | Provides an interface for working with 'RStudio' preference files to modify settings and addin shortcuts without using point-and-click option menus. Useful for ensuring a unified experience across devices and for enforcing best practices. Also exposes some settings not available in the Global Options dialog. |
| Authors: | S.A. van der Wulp [aut, cre, cph], Daniel D. Sjoberg [aut, cph] (ORCID: <https://orcid.org/0000-0003-0862-2018>) |
| Maintainer: | S.A. van der Wulp <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.3.0.9000 |
| Built: | 2026-10-09 16:49:03 UTC |
| Source: | https://github.com/vdwulp/rstudio.prefs |
Return error if minimum version requirement not met.
check_min_rstudio_version(version)check_min_rstudio_version(version)
version |
string of min required version number |
Called for its side effect; aborts with an error if the version requirement is not met, otherwise returns invisibly.
Daniel D. Sjoberg
if (interactive()) { check_min_rstudio_version("1.3") }if (interactive()) { check_min_rstudio_version("1.3") }
Fetches the listing of supported preferences from the RStudio documentation.
fetch_rstudio_prefs()fetch_rstudio_prefs()
Only preferences of type "boolean", "string", "number", "integer" and
"array" are returned. Preferences of type "object" are currently not
supported and are ignored.
A tibble containing the RStudio preference definitions.
fetch_rstudio_prefs()fetch_rstudio_prefs()
Wrapper to execute fs::path_norm() as a shortcut on highlighted text. The
updated text will be converted in place to a path normalized for the
environment currently in use. For instance, \ or \\ will be converted to /
on Windows machines. See below for process of setting a shortcut.
make_path_norm()make_path_norm()
To add a keyboard shortcut for make_path_norm() in RStudio, use the
use_rstudio_keyboard_shortcut() function as shown in the example. This
demonstrates the use of rstudio.prefs to set a keyboard shortcut.
To add a keyboard shortcut manually, follow these steps:
Install rstudio.prefs,
Restart RStudio,
Select Tools > Modify Keyboard Shortcuts...,
In the Search box, type Make Path Normal,
In the Shortcut column click on the Make Path Normal row,
Press intended shortcut keys to set shortcut (suggested: Ctrl+Shift+/).
NOTE: It is possible to override a previously specified key combination with this selection.
if (interactive()) { # Set a keyboard shortcut for path normalization rstudio.prefs::use_rstudio_keyboard_shortcut( "Ctrl+Shift+/" = "rstudio.prefs::make_path_norm" ) }if (interactive()) { # Set a keyboard shortcut for path normalization rstudio.prefs::use_rstudio_keyboard_shortcut( "Ctrl+Shift+/" = "rstudio.prefs::make_path_norm" ) }
The secondary repo string uses | to separate the repo names and their
values, as well as two different repos, e.g.
'ropensci|https://ropensci.r-universe.dev|username|https://username.r-universe.dev'.
repo_string_as_named_list(x)repo_string_as_named_list(x)
x |
secondary repository string from
|
named list
Daniel D. Sjoberg (2021-2022)
S.A. van der Wulp (since 2026)
repo_string_as_named_list( 'ropensci|https://ropensci.r-universe.dev|username|https://username.r-universe.dev' )repo_string_as_named_list( 'ropensci|https://ropensci.r-universe.dev|username|https://username.r-universe.dev' )
Copy of the internal function usethis:::rstudio_config_path()
rstudio_config_path(...)rstudio_config_path(...)
... |
strings added to the RStudio config path |
path string to RStudio rstudio-prefs.json file
Daniel D. Sjoberg
if (interactive()) { rstudio_config_path() }if (interactive()) { rstudio_config_path() }
This function updates the RStudio keyboard shortcuts saved in
the addins.json file.
use_rstudio_keyboard_shortcut(..., .write_json = TRUE, .backup = TRUE)use_rstudio_keyboard_shortcut(..., .write_json = TRUE, .backup = TRUE)
... |
series of RStudio keyboard shortcuts to update. The argument
name is the keyboard shortcut, and the value is a string of the function
name that will execute, or |
.write_json |
logical indicating whether to update and overwrite
the existing JSON file of options. Default is |
.backup |
logical indicating whether to create a back-up of shortcuts
file before it's updated. Default is |
When .write_json = FALSE, a named list of all shortcuts including
the updates. Otherwise NULL invisibly.
Daniel D. Sjoberg (2021-2022)
S.A. van der Wulp (since 2026)
# Add a shortcut use_rstudio_keyboard_shortcut( "Ctrl+Shift+/" = "rstudio.prefs::make_path_norm" ) # Remove a shortcut use_rstudio_keyboard_shortcut( "Ctrl+Shift+/" = NULL )# Add a shortcut use_rstudio_keyboard_shortcut( "Ctrl+Shift+/" = "rstudio.prefs::make_path_norm" ) # Remove a shortcut use_rstudio_keyboard_shortcut( "Ctrl+Shift+/" = NULL )
Updates RStudio preferences in rstudio-prefs.json.
use_rstudio_prefs(...)use_rstudio_prefs(...)
... |
a series of RStudio preferences to update, e.g.
|
Preference names, types, and allowed string values are validated against the official RStudio preference definitions before applying changes. A full listing of preferences is available in the RStudio documentation.
Invisibly returns the updated preferences as a named list on success,
or NULL if no updates were made (no changes, user aborted, or not in an
interactive session).
Daniel D. Sjoberg (2021-2022)
S.A. van der Wulp (since 2026)
# Pass preferences individually use_rstudio_prefs( always_save_history = FALSE, rainbow_parentheses = TRUE ) # Pass a list of preferences pref_list <- list(always_save_history = FALSE, rainbow_parentheses = TRUE) use_rstudio_prefs(!!!pref_list) # Pass array type preference use_rstudio_prefs( busy_exclusion_list = list("tmux", "screen") )# Pass preferences individually use_rstudio_prefs( always_save_history = FALSE, rainbow_parentheses = TRUE ) # Pass a list of preferences pref_list <- list(always_save_history = FALSE, rainbow_parentheses = TRUE) use_rstudio_prefs(!!!pref_list) # Pass array type preference use_rstudio_prefs( busy_exclusion_list = list("tmux", "screen") )
Updates the secondary repositories in rstudio-prefs.json.
use_rstudio_secondary_repo(...)use_rstudio_secondary_repo(...)
... |
a series of named secondary repositories, e.g.
|
Invisibly returns the updated cran_mirror preference as a named
list on success, or NULL if no updates were made (no changes, user
aborted, or not in an interactive session).
Daniel D. Sjoberg (2021-2022)
S.A. van der Wulp (since 2026)
# Add a repository use_rstudio_secondary_repo( ropensci = "https://ropensci.r-universe.dev", username = "https://username.r-universe.dev" ) # Remove a repository use_rstudio_secondary_repo(ropensci = NULL)# Add a repository use_rstudio_secondary_repo( ropensci = "https://ropensci.r-universe.dev", username = "https://username.r-universe.dev" ) # Remove a repository use_rstudio_secondary_repo(ropensci = NULL)