| Title: | Set 'RStudio' Preferences |
|---|---|
| Description: | As of 'RStudio' v1.3, the preferences in the Global Options dialog (and a number of other preferences that aren’t) are now saved in simple, plain-text JSON files. This package provides an interface for working with these 'RStudio' JSON preference files to easily make modifications without using the point-and-click option menus. This is particularly helpful when working on teams to ensure a unified experience across machines and utilizing settings for best practices. |
| Authors: | Daniel D. Sjoberg [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-0862-2018>) |
| Maintainer: | Daniel D. Sjoberg <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.9.9000 |
| Built: | 2026-05-25 08:32:25 UTC |
| Source: | https://github.com/ddsjoberg/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 |
path string to RStudio rstudio-prefs.json file
Daniel D. Sjoberg
if (interactive()) { check_min_rstudio_version() }if (interactive()) { check_min_rstudio_version() }
Preferences are fetched from https://docs.rstudio.com/ide/server-pro/session-user-settings.html
fetch_rstudio_prefs()fetch_rstudio_prefs()
tibble
Only preferences of type "boolean", "string", "number", "integer",
and "array"
are fetched from the table.
TODO: Research how type "object" are passed and include
in the fetched preferences table.
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 shortcut.
make_path_norm()make_path_norm()
Add keyboard shortcut for make_path_norm() in RStudio, use the
use_rstudio_keyboard_shortcut() function. Do add it manually,
follow the instructions below.
Install rstudio.prefs, and restart RStudio
Select "Tools" –> "Modify Keyboard Shortcuts...".
In Search box, type "Make Path Normal".
Click in the "Shortcut" column on the "Make Path Normal" row.
Press intended shortcut keys (suggested: Ctrl+Shift+/) to set shortcut.
NOTE: It is possible to override a previously specified key combination with this selection.
normalized path string
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|ddsjoberg|https://ddsjoberg.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
repo_string_as_named_list( 'ropensci|https://ropensci.r-universe.dev|ddsjoberg|https://ddsjoberg.r-universe.dev' )repo_string_as_named_list( 'ropensci|https://ropensci.r-universe.dev|ddsjoberg|https://ddsjoberg.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. See examples. |
.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 preferences
file before it's updated. Default is |
NULL, updates RStudio addins.json file
Daniel D. Sjoberg
use_rstudio_keyboard_shortcut( "Ctrl+Shift+/" = "rstudio.prefs::make_path_norm" )use_rstudio_keyboard_shortcut( "Ctrl+Shift+/" = "rstudio.prefs::make_path_norm" )
This function updates the RStudio preferences saved in
the rstudio-prefs.json file. A full listing of preferences that may be
modified are listed here
https://docs.rstudio.com/ide/server-pro/session-user-settings.html
use_rstudio_prefs(...)use_rstudio_prefs(...)
... |
series of RStudio preferences to update, e.g.
|
NULL, updates RStudio rstudio-prefs.json file
Daniel D. Sjoberg
# 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 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)
This function updates the RStudio preferences saved in
the rstudio-prefs.json file to include the secondary repositories
passed my the user. If a new name for an existing repository is
passed by the user, the name will be updated in the JSON file.
use_rstudio_secondary_repo(...)use_rstudio_secondary_repo(...)
... |
series of named secondary repositories, e.g.
|
A note for users outside of the USA.
If the country in .$cran_mirror$country has not been previously recorded
in the JSON preferences file (typically, auto set by RStudio),
the use_rstudio_secondary_repo() function will set "country" = "us".
NULL, updates RStudio rstudio-prefs.json file
Daniel D. Sjoberg
use_rstudio_secondary_repo( ropensci = "https://ropensci.r-universe.dev", ddsjoberg = "https://ddsjoberg.r-universe.dev" )use_rstudio_secondary_repo( ropensci = "https://ropensci.r-universe.dev", ddsjoberg = "https://ddsjoberg.r-universe.dev" )