knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of rsprefs is to help you manage your RStudio preferences.
You can install the development version of rsprefs from GitHub with:
# install.packages("remotes") remotes::install_github("gadenbuie/rsprefs")
library(rsprefs)
path = "new private gist"
to keep your preferences private.r
snapshot_prefs_save(name = "sync", path = "new gist")
``
✓ Created gist with id 96e8c7f0a624bfed8018987185feb30b
ℹ Use this gist automatically by adding the following to your ~/.Rprofile.
Call
usethis::edit_r_profile()`
options(rsprefs.gist_id = "96e8c7f0a624bfed8018987185feb30b")
✓ Creating gist with user-prefs.json ... done ✓ Writing snapshot sync to new gist ... done ```
Open your ~/.Rprofile
using usethis::edit_r_profile()
and add the rsprefs.gist_id
option from the output above.
If you change your IDE preferences you can update your snapshot by name, using the gist ID found from the global option.
r
snapshot_prefs_save("sync", overwrite = TRUE)
rsprefs.gist_id
option and then apply your snapshot.r
snapshot_prefs_use("sync")
rsprefs stores snapshots of your RStudio preferences. A snapshot can contain all of your preferences, or just a small selection of preferences. Snapshots are named and can be stored locally or in a GitHub gist.
By default, rsprefs will store snapshots in a JSON file in rappdirs::user_config_dir("rsprefs")
,
but you can choose where to store snapshots with the path
argument.
In these examples, I'll use a temporary file for demonstration purposes. Here I'll take a snapshot of my current preferences.
tmp_snap <- "tmp_snap.json" snapshot_prefs_save("demo", path = tmp_snap)
You can list available preference snapshots with snapshot_prefs_list()
snapshot_prefs_list(path = tmp_snap)
or you can apply the preferences in a snapshot with snapshot_prefs_use()
.
(You can also set preview = TRUE
to preview the preferences included in the snapshot without applying them.)
snapshot_prefs_use( name = "demo", path = tmp_snap, preview = TRUE )
If you apply the snapshot and change your mind, you can roll back the changes from the snapshot by calling snapshot_prefs_undo()
.
Snapshots don't need to include every preference in RStudio. Instead, you can use snapshot to store specific groups of preferences. There are three arguments that control which preferences are included:
include
: Names of RStudio preferences to include.
If provided, only these preferences are included.exclude
: Names of RStudio preferences to exclude from the snapshot.source
: The source of the current preference value.
Preferences are set at different levels, from lowest to highest precedence:
"default"
are RStudio's built-in defaults
"computed"
are detected or supplied from external sources, e.g. the
path to git
on your system"system"
are derived from system-wide rstudio-prefs.json
"user"
are set by the user for all sessions (global options)"project"
are set by the current project sessionThe default is "user"
, since these are the preferences you've most
intentionally set for your IDE. Also, "project"
preferences are already
stored in the .Rproj
file.
For example, you could store your favorite pane layout as "favorite_panes"
:
snapshot_prefs_save( name = "favorite_panes", path = tmp_snap, include = "panes" ) snapshot_prefs_use( name = "favorite_panes", path = tmp_snap, preview = TRUE )
Occasionally, you might want to reset all of your preferences to RStudio's "factory defaults", for example when teaching or working with a beginner. To quickly reset all defaults, call
prefs_reset_defaults()
If you want to return to your personal preferences, you can undo the change to the defaults with
snapshot_prefs_undo()
For a longer-term return to RStudio's defaults, make sure that you've taken a snapshot of your personal preferences before you reset.
You can obtain a list of available preferences for your version of RStudio using:
schema <- prefs_schema()
rsprefs includes the preference information for RStudio releases since 1.3.959. If you're using dailies or preview versions fo RStudio, rsprefs will attempt to download the schema that matches your version, falling back to the latest version if one is not available.
For quick reference, the latest preference details are included in the prefs_rstudio
object.
prefs_rstudio
This list contains detailed information about every preference, so you can use autocomplete to explore the preferences.
prefs_rstudio$highlight_r_function_calls
prefs_rstudio$insert_native_pipe_operator
The prefs_rstudio
object also comes with helper functions to get, set and toggle preferences:
# $get() current preference value original <- prefs_rstudio$insert_native_pipe_operator$get() original # $toggle() boolean preferences prefs_rstudio$insert_native_pipe_operator$toggle() # $set() the preference directly prefs_rstudio$insert_native_pipe_operator$set(original) # check that we've come full circle prefs_rstudio$insert_native_pipe_operator$get()
fs::file_delete(tmp_snap)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.