Last active
July 7, 2021 21:35
-
-
Save jlacko/8c6e19e59c6c78d8143e67d0f2c8eddb to your computer and use it in GitHub Desktop.
Init script for new RStudio installation, promoting best practices
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
# make certain jsonlite is available | |
if(!require(jsonlite, quietly = TRUE)) { | |
install.packages("jsonlite") | |
library(jsonlite) | |
} | |
# get the path to settings file | |
path <- if (Sys.info()[["sysname"]] == "Windows") { | |
paste0(Sys.getenv('APPDATA'), "\\RStudio\\rstudio-prefs.json") | |
} else { | |
"~/.config/rstudio/rstudio-prefs.json" | |
} | |
# is there a settings file present? | |
if(file.exists(path)) { | |
settings <- jsonlite::read_json(path) # if yes, read it in | |
} else { | |
settings <- list() # if not, initiate an empty list | |
} | |
# amend as required | |
settings["load_workspace"] <- FALSE | |
settings["save_workspace"] <- "never" | |
settings["default_encoding"] <- "UTF-8" | |
settings["always_save_history"] <- FALSE | |
settings["real_time_spellchecking"] <- FALSE | |
# save the settings & get done with it... | |
jsonlite::write_json(settings, path, auto_unbox = TRUE, pretty = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment