Last active
March 2, 2020 09:58
-
-
Save pat-s/7951c02de56803fd36c28e517199d95f to your computer and use it in GitHub Desktop.
Apply RStudio Desktop Settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"styler::style_active_file": "Ctrl+Y", | |
"addmins::insert_dashes": "Ctrl+8", | |
"xaringan::inf_mr": "Ctrl+M", | |
"drake::rs_addin_loadd": "Ctrl+K", | |
"browse::browse": "Ctrl+B" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yesno <- menu(c("Yes!", "Ehm, wait..."), | |
title = "This will overwrite all of your RStudio settings and keybindings. Do you want to continue?" | |
) | |
minimal <- menu(c( | |
"Minimal", | |
"Patrick Schratz settings (includes addins and more R packages)" | |
), | |
title = "Which installation type do you prefer?" | |
) | |
if (yesno != 1) { | |
stop("Aborting.") | |
} | |
if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes") | |
if (!requireNamespace("curl", quietly = TRUE)) install.packages("curl") | |
if (!requireNamespace("rstudioapi")) install.packages("rstudioapi") | |
if (!requireNamespace("cli")) install.packages("cli") | |
if (minimal != 1) { | |
remotes::install_github("gadenbuie/rsthemes", upgrade = "never", quiet = TRUE) | |
rsthemes::install_rsthemes() | |
rstudioapi::applyTheme("One Light {rsthemes}") | |
remotes::install_github("krlmlr/fledge") | |
remotes::install_github("pat-s/usethis@my-prs") | |
remotes::install_github("r-lib/prettycode") | |
remotes::install_github("tmastny/browse") | |
remotes::install_github("lorenzwalthert/teamtools") | |
remotes::install_github("lorenzwalthert/styler@mlr-style") | |
remotes::install_github("gadenbuie/rsthemes") | |
remotes::install_github("mine-cetinkaya-rundel/addmins") | |
install.packages(c("reprex", "remotes", "startup")) | |
} | |
# Check if RStudio > 1.3 is installed ------------------------------------------ | |
if (unlist(rstudioapi::getVersion())[2] < 3) { | |
cli::cli_alert_danger("You need a newer version of RStudio.") | |
cli::cli_text("Please go to {.url https://dailies.rstudio.com/} and download | |
version 1.3.x or greater.", wrap = TRUE) | |
stop() | |
} | |
# check if RTools is installed on Windows -------------------------------------- | |
if (Sys.info()[["sysname"]] == "Windows") { | |
# need pkgbuild to check for RTools installation | |
if (!requireNamespace("pkgbuild", quietly = TRUE)) install.packages("pkgbuild", type = "binary") | |
if (pkgbuild::rtools_path() == "") { | |
cli::cli_alert_info("Installing `RTools`. This is required to | |
install R packages from source.", wrap = TRUE) | |
if (!requireNamespace("installr", quietly = TRUE)) install.packages("installr") | |
installr::install.Rtools(choose_version = FALSE, check = FALSE) | |
} | |
} | |
# install utils ---------------------------------------------------------------- | |
if (!requireNamespace("jsonlite", quietly = TRUE)) install.packages("jsonlite") | |
if (minimal != 1) { | |
cli::cli_alert_info("Starting to install dependencies for RStudio Addins. Please be patient.") | |
} | |
cli::cat_rule() | |
# setup spinner | |
sp1 <- cli::make_spinner() | |
fun_with_spinner <- function() { | |
sp1$spin() | |
# addins --------------------------------------------------------------------- | |
if (!minimal) { | |
remotes::install_github("mine-cetinkaya-rundel/addmins", quiet = TRUE) | |
if (!requireNamespace("xaringan", quietly = TRUE)) install.packages("xaringan") | |
if (!requireNamespace("styler", quietly = TRUE)) install.packages("styler") | |
} | |
# scrape settings from gist ---------------------------------------------------- | |
if (minimal != 1) { | |
keybindings <- jsonlite::fromJSON("https://gist.githubusercontent.com/pat-s/7951c02de56803fd36c28e517199d95f/raw/1f1b301209b1b198f03eceb0536ad243c8a45081/rstudio_bindings-patrick.json") | |
general <- jsonlite::fromJSON("https://gist.githubusercontent.com/pat-s/7951c02de56803fd36c28e517199d95f/raw/1f1b301209b1b198f03eceb0536ad243c8a45081/rstudio-prefs-patrick.json") | |
addins <- jsonlite::fromJSON("https://gist.githubusercontent.com/pat-s/7951c02de56803fd36c28e517199d95f/raw/1f1b301209b1b198f03eceb0536ad243c8a45081/addins.json") | |
} else { | |
keybindings <- jsonlite::fromJSON("https://gist.githubusercontent.com/pat-s/7951c02de56803fd36c28e517199d95f/raw/1f1b301209b1b198f03eceb0536ad243c8a45081/rstudio_bindings-minimal.json") | |
general <- jsonlite::fromJSON("https://gist.github.com/pat-s/7951c02de56803fd36c28e517199d95f/raw/1f1b301209b1b198f03eceb0536ad243c8a45081/rstudio-prefs-minimal.json") | |
} | |
# install on user machine ---------------------------------------------------- | |
switch(Sys.info()[["sysname"]], | |
Windows = { | |
dir.create("~/../AppData/Roaming/RStudio/keybindings", showWarnings = FALSE) | |
jsonlite::write_json(keybindings, | |
"~/../AppData/Roaming/RStudio/keybindings/rstudio_bindings.json", | |
pretty = TRUE, , auto_unbox = TRUE | |
) | |
}, | |
Linux = { | |
dir.create("~/.config/rstudio/keybindings", showWarnings = FALSE) | |
jsonlite::write_json(keybindings, | |
"~/.config/rstudio/keybindings/rstudio_bindings.json", | |
pretty = TRUE, auto_unbox = TRUE | |
) | |
}, | |
Darwin = { | |
dir.create("~/.config/rstudio/keybindings", showWarnings = FALSE) | |
jsonlite::write_json(keybindings, | |
"~/.config/rstudio/keybindings/rstudio_bindings.json", | |
pretty = TRUE, auto_unbox = TRUE | |
) | |
} | |
) | |
switch(Sys.info()[["sysname"]], | |
Windows = { | |
jsonlite::write_json(general, | |
"~/../AppData/Roaming/RStudio/rstudio-prefs.json", | |
pretty = TRUE, auto_unbox = TRUE | |
) | |
}, | |
Linux = { | |
jsonlite::write_json(general, | |
"~/.config/rstudio/rstudio-prefs.json", | |
pretty = TRUE, auto_unbox = TRUE | |
) | |
}, | |
Darwin = { | |
jsonlite::write_json(general, | |
"~/.config/rstudio/rstudio-prefs.json", | |
pretty = TRUE, auto_unbox = TRUE | |
) | |
} | |
) | |
if (minimal != 1) { | |
switch(Sys.info()[["sysname"]], | |
Windows = { | |
jsonlite::write_json(addins, | |
"~/../AppData/Roaming/RStudio/keybindings/addins.json", | |
pretty = TRUE, auto_unbox = TRUE | |
) | |
}, | |
Linux = { | |
jsonlite::write_json(addins, | |
"~/.config/rstudio/keybindings/addins.json.json", | |
pretty = TRUE, auto_unbox = TRUE | |
) | |
}, | |
Darwin = { | |
jsonlite::write_json(addins, | |
"~/.config/rstudio/keybindings/addins.json", | |
pretty = TRUE, auto_unbox = TRUE | |
) | |
} | |
) | |
} | |
sp1$finish() | |
} | |
cli::ansi_with_hidden_cursor(fun_with_spinner()) | |
if (minimal != 1) { | |
cli::cli_alert_success("Successfully installed Patrick's RStudio settings.") | |
} else { | |
cli::cli_alert_success("Successfully supercharged your RStudio settings.") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"save_workspace": "never", | |
"highlight_selected_line": true, | |
"syntax_color_console": true, | |
"highlight_r_function_calls": true, | |
"auto_append_newline": true, | |
"strip_trailing_whitespace": true, | |
"check_arguments_to_r_function_calls": true, | |
"warn_variable_defined_but_not_used": true, | |
"busy_detection": "never", | |
"save_files_before_build": true, | |
"pdf_previewer": "none", | |
"show_invisibles": true, | |
"rmd_chunk_output_inline": false, | |
"show_rmd_render_command": true, | |
"real_time_spellchecking": true, | |
"rmd_viewer_type": "pane", | |
"source_with_echo": true, | |
"show_hidden_files": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"panes": { | |
"quadrants": [ | |
"Source", | |
"TabSet1", | |
"Console", | |
"TabSet2" | |
], | |
"tabSet1": [ | |
"History", | |
"Presentation" | |
], | |
"tabSet2": [ | |
"Environment", | |
"Files", | |
"Plots", | |
"Connections", | |
"Packages", | |
"Help", | |
"Build", | |
"VCS", | |
"Viewer" | |
], | |
"console_left_on_top": false, | |
"console_right_on_top": true | |
}, | |
"save_workspace": "never", | |
"highlight_selected_line": true, | |
"syntax_color_console": true, | |
"highlight_r_function_calls": true, | |
"auto_append_newline": true, | |
"strip_trailing_whitespace": true, | |
"check_arguments_to_r_function_calls": true, | |
"warn_variable_defined_but_not_used": true, | |
"busy_detection": "never", | |
"editor_theme": "One Light {rsthemes}", | |
"save_files_before_build": true, | |
"pdf_previewer": "none", | |
"show_invisibles": true, | |
"rmd_chunk_output_inline": false, | |
"show_rmd_render_command": true, | |
"real_time_spellchecking": true, | |
"rmd_viewer_type": "pane", | |
"source_with_echo": true, | |
"show_hidden_files": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"goToFileFunction": "Ctrl+P", | |
"insertPipeOperator": "Ctrl+O", | |
"restartR": "Ctrl+R", | |
"activateTerminal": "Ctrl+3", | |
"newTerminal": "Ctrl+4", | |
"previousTerminal": "Ctrl+5", | |
"nextTerminal": "Ctrl+6", | |
"sendTerminalToEditor": "", | |
"activateVcs": "Ctrl+7", | |
"switchToTab": "Ctrl+T", | |
"previousTab": "Ctrl+N", | |
"nextTab": "Ctrl+M", | |
"closeAllTerminals": "Alt+Shift+S" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"goToFileFunction": "Ctrl+P", | |
"insertPipeOperator": "Ctrl+O", | |
"restartR": "Ctrl+R", | |
"activateTerminal": "Ctrl+3", | |
"sendTerminalToEditor": "", | |
"newTerminal": "Ctrl+4", | |
"previousTerminal": "Ctrl+5", | |
"nextTerminal": "Ctrl+6", | |
"activateVcs": "Ctrl+7", | |
"switchToTab": "Ctrl+T", | |
"previousTab": "Ctrl+N", | |
"nextTab": "Ctrl+M", | |
"closeAllTerminals": "Alt+Shift+S" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shortcut
source("https://bit.ly/rstudio-pat")