Skip to content

Instantly share code, notes, and snippets.

@jlacko
Last active July 7, 2021 21:35
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jlacko/8c6e19e59c6c78d8143e67d0f2c8eddb to your computer and use it in GitHub Desktop.
Save jlacko/8c6e19e59c6c78d8143e67d0f2c8eddb to your computer and use it in GitHub Desktop.
Init script for new RStudio installation, promoting best practices
# 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