The goal of RStudioBackupPrefs is to provide an easy and online way to backup and restore your R Studio preferences. For reference, the following files are backed up :
-
addins.json
-
rstudio_bindings.json
-
rstudio-prefs.json
-
r.snippets
Credits to pat-s/rstudioSettings for the idea and getting inspiration from the backup code.
You can install the development version of RStudioBackupPrefs from GitHub with:
install.packages("devtools")
devtools::install_github("Minh-AnhHuynh/RStudioBackupPrefs")
# Alternatively
install.packages("librarian")
librarian::shelf("Minh-AnhHuynh/RStudioBackupPrefs")
# librarian::shelf() will install or load the package if already installed.
# You can queue up multiple package in one line.
The idea is to install this package on a new R project or machine, import your preferences from GitHub by first cloning the repository containing your rstudio preference files and copying them to the relevant RStudio preference folder.
For backing up, the idea is to upload your current RStudio settings to the currently git initiated repository, or to choose a dedicated git repository for your RStudio settings and thus another folder on your local machine.
library(RStudioBackupPrefs)
start_backup_prefs(github_backup = TRUE)
Back up using a specific folder containing your preference files. If your working directory is currently inside an R project, you’d want to specify the path to the R folder that is outside of your current one (else it’s the same as the current one)
start_backup_prefs(github_backup = TRUE, repository = "../MyRStudioPrefs")
The function will pull from GitHub by default, and will to copy the files to the rstudio preference folder (import).
Note that you have to specify the folder where our RStudio preference
files are backed up, which should be in the same folder, obtained
through the start_backup_prefs()
function. For example,
start_backup_prefs(preference_path = "R/rstudio_preferences")
will
create a folder named R/rstudio_preferences/
in the current working
directory.
You are required to clone the repository containing your preferences first. For convenience you can clone a GitHub folder and copy with the same function.
Use clone_git = TRUE
, the function will ask for the git url and list
the GitHub repositories under the current git username
start_import_prefs(clone_git = TRUE)
You can specify the git url directly. Use list_github_repositories()
to list the repositories under your current git username.
list_github_repositories()
start_import_prefs(clone_git = TRUE, git_url = "https://github.com/cran/dummies")
Specify the clone path if you want to clone to a specific folder.
start_import_prefs(clone_git = TRUE, git_path = "../MyRStudioPrefs")
start_import_prefs(preference_path = "R/rstudio_preferences/")
git pull
will work inside a git folder regardless of the file path.
start_import_prefs("../MyRStudioPrefs/R/rstudio_preferences/")
start_import_prefs(preference_path = "R/rstudio_preferences/", pull_github = FALSE)
# Choose a path
start_backup_prefs(preference_path = "R/rstudio_preferences", copy_to_local = TRUE)
# If you are fine with leaving files in your RStudio preference folder
start_backup_prefs()
# Use open_backup_path = TRUE to see the RStudio preference folder
start_backup_prefs(open_backup_path = TRUE)
Use start_import_prefs(pull_github = FALSE)
to import your preferences
from the local folder.
To use the GitHub functionalities, you need to have an initiated repository. Simply initiate one with:
# Assuming you're in your desired folder path:
usethis::use_git()
usethis::use_github()
# Optional:
usethis::git_vaccinate()
# Set your credentials if needed:
gitcreds::gitcreds_set()
Make sure to put your user.name and user.email in global config. To do so, go to Terminal and write:
git init
git config --global user.name "YOUR FULL NAME"
git config --global user.email "YOUR EMAIL ADDRESS"
Check out Happy Git with R for more information.