diff --git a/.Rbuildignore b/.Rbuildignore index 4c39bbd..8cfd41d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,4 +5,6 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +# other ^LICENSE\.md$ +^README\.Rmd$ diff --git a/.gitignore b/.gitignore index a14fbca..a986fb2 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,10 @@ vignettes/*.pdf *.utf8.md *.knit.md .Rproj.user + +# System-specific temp, backup, thumbnail etc. files +.~lock* +*.backup +~$* +.DS_Store +Thumbs.db diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..ba22fdd --- /dev/null +++ b/.lintr @@ -0,0 +1,12 @@ +linters: with_defaults(absolute_path_linter = absolute_path_linter, + implicit_integer_linter = implicit_integer_linter, + line_length_linter = line_length_linter(160), + nonportable_path_linter = nonportable_path_linter, + object_length_linter = lintr::object_length_linter(40), + semicolon_terminator_linter = semicolon_terminator_linter, + todo_comment_linter = todo_comment_linter, + trailing_whitespace_linter = NULL, + T_and_F_symbol_linter = T_and_F_symbol_linter, + undesirable_function_linter = undesirable_function_linter, + undesirable_operator_linter = undesirable_operator_linter(c(lintr:::default_undesirable_operators, `->` = NA)), + unneeded_concatenation_linter = unneeded_concatenation_linter) diff --git a/DESCRIPTION b/DESCRIPTION index c72a447..30eda8e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,15 +1,39 @@ Package: rscodeio -Title: A VSCode skin for RStudio -Version: 0.1.0 -Authors@R: c(person("Anthony", "North", email = "anthony.jl.north@gmail.com", role = c("aut", "cre")), - person("Miles", "McBain", email = "miles.mcbain@gmail.com", role = "ctb")) -Description: It really just modifies RStudio presentation. -Depends: R (>= 3.3.0) +Title: An RStudio Theme Inspired by Visual Studio Code +Version: 0.1.9000 +Authors@R: + c(person(given = "Anthony", + family = "North", + role = c("aut", "cre"), + email = "anthony.jl.north@gmail.com"), + person(given = "Miles", + family = "McBain", + role = "ctb", + email = "miles.mcbain@gmail.com"), + person(given = "Salim", + family = "Brüggemann", + role = "ctb", + email = "salim-b@pm.me", + comment = c(ORCID = "0000-0002-5329-5987"))) +Description: This package provides two greyish dark RStudio + editor themes which only differ in the syntax highlighting style: + while 'rscodeio' offers the colors found in Visual Studio Code, + 'Tomorrow Night Bright (rscodeio)' combines this package's dark + interface theming with the syntax highlighting colors from the + similarly named editor theme provided by RStudio. Furthermore, both + themes style RStudio's menu, something which is not exposed by the + current theming API and therefore requires administrator privileges to + replace the relevant QSS files. License: MIT + file LICENSE -Encoding: UTF-8 -LazyData: true +Depends: + R (>= 3.3.0) Imports: fs, + glue, purrr, + rlang, rstudioapi -RoxygenNote: 7.1.1 +Encoding: UTF-8 +LazyData: true +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.1.2 diff --git a/NAMESPACE b/NAMESPACE index 669232c..42ffd9c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -export(activate_menu_theme) -export(deactivate_menu_theme) -export(install_theme) -export(uninstall_theme) +export(install_menu_theme) +export(install_themes) +export(uninstall_menu_theme) +export(uninstall_themes) diff --git a/R/rscodeio.R b/R/rscodeio.R index 84fce56..9ba2f1b 100644 --- a/R/rscodeio.R +++ b/R/rscodeio.R @@ -1,120 +1,180 @@ -#' Install the rscodeio theme +#' Install rscodeio editor themes and menu bar styling #' -#' You'll need RStudio at least 1.2.x and if your RStudio -#' is installed to a default location on Windows or Linux, -#' you'll need to be running RStudio as -#' Administrator to install the menu theme files (Just required for install). +#' RStudio 1.2 or later is required for this. Additionally, administrator privileges are required to also install the Qt Style Sheet (QSS) files to style +#' RStudio's menu bar, something which is not possible with [RStudio's current theming +#' API](https://rstudio.github.io/rstudio-extensions/rstudio-theme-creation.html). #' -#' You can elect not to install the menu theme files with `menus = FALSE`. +#' # Menu bar styling #' -#' @param menus if FALSE do not install the RStudio menu theme qss files. -#' @return nothing. +#' On Linux, it will be asked interactively for administrator credentials by calling [Polkit](https://en.wikipedia.org/wiki/Polkit)'s +#' [`pkexec`](https://www.freedesktop.org/software/polkit/docs/latest/pkexec.1.html). Windows users must run RStudio as administrator in order to install +#' rscodeio's menu bar styling. On macOS and RStudio Server, menu bar styling is not necessary and thus always skipped. +#' +#' The installation of the QSS files styling the menu bar can be skipped by setting `style_menu_bar = FALSE`. See [install_menu_theme()] for more details about +#' the menu bar styling. +#' +#' Note that the menu bar styling has to be reapplied after _every_ update or reinstallation of RStudio. This is because the custom QSS files provided by +#' rscodeio get overwritten during RStudio's installation process. +#' +#' @param apply_theme The rscodeio editor theme variant to apply. All variants are installed and the one specified here is activated right away. The other +#' variants can be selected anytime later in RStudio's global options. Variation only affects the syntax highlighting and terminal styling. One of +#' - `"rscodeio"` for the default color variant inspired by Visual Studio Code. +#' - `"Tomorrow Night Bright (rscodeio)"` for the colors known from the similarly named default RStudio theme. +#' @param style_menu_bar Whether to also install rscodeio's custom QSS files to style RStudio's menu bar. Administrator privileges are required. +#' @param install_globally Whether to install the editor themes for the current user (`FALSE`) or all users globally (`TRUE`). The latter may require +#' administrator privileges. +#' @return Nothing (`NULL` invisibly). #' @export -install_theme <- function(menus = TRUE) { - - ## check RStudio API available - if(!rstudioapi::isAvailable()) stop("RSCodeio must be installed from within RStudio.") +install_themes <- function(apply_theme = c("rscodeio", + "Tomorrow Night Bright (rscodeio)"), + style_menu_bar = TRUE, + install_globally = FALSE) { + + # ensure RStudio API is available + if (!rstudioapi::isAvailable()) { + stop("rscodeio must be installed from within RStudio.", + call. = FALSE) + } - ## check RStudio supports themes - if(utils::compareVersion(as.character(rstudioapi::versionInfo()$version), "1.2.0") < 0) - stop("You need RStudio 1.2 or greater to get theme support") + # ensure minimally required RStudio version + if (rstudioapi::versionInfo()$version < as.package_version("1.2.0")) + stop("You need RStudio 1.2 or later to get theme support", + call. = FALSE) - ## check if menu theme already installed and uninstall - if(rscodeio_installed()){ - uninstall_theme() - } + # add the editor theme variants + ## existing editor themes of the same names have to be removed first + uninstall_themes(restore_menu_bar = FALSE) - ## add the themes - rscodeio_default_theme <- rstudioapi::addTheme(fs::path_package(package = "rscodeio", - "resources","rscodeio.rstheme")) - - rstudioapi::addTheme(fs::path_package(package = "rscodeio", - "resources","rscodeio_tomorrow_night_bright.rstheme")) + purrr::walk(.x = c("rscodeio.rstheme", + "rscodeio_tomorrow_night_bright.rstheme"), + .f = ~ rstudioapi::addTheme(fs::path_package(package = "rscodeio", + "resources", .x), + globally = install_globally)) - ## add the custom Qt CSS - if (menus) activate_menu_theme() + # add the custom QSS files + if (style_menu_bar) install_menu_theme(reload_editor_theme = FALSE) - ## activate default rscodeio theme - rstudioapi::applyTheme(rscodeio_default_theme) + # activate chosen rscodeio editor theme variant + rstudioapi::applyTheme(rlang::arg_match(apply_theme)) } -#' Uninstall the rscodeio theme +#' Uninstall the rscodeio editor themes and menu bar styling +#' +#' To restore RStudio's default _dark_ Qt Style Sheet (QSS) files (i.e. setting `restore_menu_bar = TRUE`), administrator privileges are required. On Linux, it +#' will be asked interactively for administrator credentials by calling [Polkit](https://en.wikipedia.org/wiki/Polkit)'s +#' [`pkexec`](https://www.freedesktop.org/software/polkit/docs/latest/pkexec.1.html). Windows users must run RStudio as administrator in order to uninstall +#' rscodeio's menu bar styling. On macOS and RStudio Server, menu bar styling is not necessary and thus its menu bar restoration will be skipped. #' -#' @return nothing. +#' @param restore_menu_bar Whether to restore RStudio's default menu bar styling. Irrelevant if rscodeio menu bar styling is not installed (see +#' [install_menu_theme()] for details about menu bar styling). +#' @return Nothing (`NULL` invisibly). #' @export -uninstall_theme <- function(){ - - deactivate_menu_theme() - - installed_rscodeio_themes <- grep(x = purrr::map_depth(.x = rstudioapi::getThemes(), - .depth = 1L, - .f = purrr::pluck("name")), - pattern = "rscodeio", - value = TRUE) - - for (theme in installed_rscodeio_themes) { - rstudioapi::removeTheme(theme) - } -} +uninstall_themes <- function(restore_menu_bar = TRUE) { + + if (restore_menu_bar) uninstall_menu_theme() + purrr::walk(.x = installed_rscodeio_editor_themes(), + .f = rstudioapi::removeTheme) +} -#' Activate rscodeio styling in file menu. +#' Install rscodeio menu bar styling +#' +#' This function overwrites RStudio's default _dark_ [Qt Style Sheet (QSS)](https://doc.qt.io/Qt-5/stylesheet-syntax.html) files with rscodeio's customized ones +#' in order to properly style RStudio's menu bar which cannot be altered by [RStudio's current theming +#' API](https://rstudio.github.io/rstudio-extensions/rstudio-theme-creation.html). The original Qt Style Sheet files are backed up and can be restored by +#' calling [uninstall_menu_theme()]. +#' +#' Running [`install_themes(style_menu_bar = TRUE)`][install_themes()] (which is the default) has the same effect as running this function. +#' `install_menu_theme()` can be useful to install the rscodeio menu bar styling _without_ the accompanying editor themes. #' -#' @return nothing. +#' Administrator privileges are required to copy the QSS files to RStudio's installation directory. On Linux, it will be asked interactively for administrator +#' credentials by calling [Polkit](https://en.wikipedia.org/wiki/Polkit)'s [`pkexec`](https://www.freedesktop.org/software/polkit/docs/latest/pkexec.1.html). +#' Windows users must run RStudio as administrator On macOS and RStudio Server, menu bar styling is not necessary and running this function has no effect. +#' +#' Note that this function has to be executed again after _every_ update or reinstallation of RStudio. This is because the custom QSS files provided by rscodeio +#' get overwritten during RStudio's installation process. +#' +#' @param reload_editor_theme Whether to reload the editor theme upon installing rscodeio's menu bar styling. This is necessary for the changes to take effect +#' immediately. Otherwise, the changes will only become visible after a restart of RStudio. +#' @return Nothing (`NULL` invisibly). #' @export -activate_menu_theme <- function() { +install_menu_theme <- function(reload_editor_theme = TRUE) { - ## Styling menus not supported on Mac or RStudio Server. - if(host_os_is_mac() | is_rstudio_server()) return(NULL) + # menu bar styling is not supported on macOS or RStudio Server + if (is_macos() || is_rstudio_server()) return(NULL) - if(file.exists(gnome_theme_dark_backup()) | - file.exists(windows_theme_dark_backup())) { - message("RSCodeio menu theme already activated. Deactivate first.") - return(FALSE) - } + process_menu_themes(backup_gnome = !is_rscodeio_menu_theme(path_theme_dark_gnome()), + backup_windows = !is_rscodeio_menu_theme(path_theme_dark_windows()), + override_gnome = TRUE, + override_windows = TRUE) - ## backup dark Qt themes - file.copy(from = gnome_theme_dark(), - to = gnome_theme_dark_backup()) - file.copy(from = windows_theme_dark(), - to = windows_theme_dark_backup()) - - ## replace with RSCodeio Qt themes - file.copy(from = system.file(fs::path("resources","stylesheets","rstudio-gnome-dark.qss"), - package = "rscodeio"), - to = gnome_theme_dark(), - overwrite = TRUE) - file.copy(from = system.file(fs::path("resources","stylesheets","rstudio-windows-dark.qss"), - package = "rscodeio"), - to = windows_theme_dark(), - overwrite = TRUE) + if (reload_editor_theme) rstudioapi::applyTheme(rstudioapi::getThemeInfo()$editor) } -#' Deactivate rscodeio style in file menu. +#' Uninstall rscodeio menu bar styling +#' +#' This function restores RStudio's default _dark_ Qt [Qt Style Sheet (QSS)](https://doc.qt.io/Qt-5/stylesheet-syntax.html) files. #' -#' @return nothing. +#' Running [`uninstall_themes(restore_menu_bar = TRUE)`][uninstall_themes()] (which is the default) has the same effect as running this function. +#' `uninstall_menu_theme()` can be useful to remove the rscodeio menu bar styling _without_ removing the accompanying editor themes. +#' +#' Administrator privileges are required to restore RStudio's default QSS files. On Linux, it will be asked interactively for administrator credentials by +#' calling [Polkit](https://en.wikipedia.org/wiki/Polkit)'s [`pkexec`](https://www.freedesktop.org/software/polkit/docs/latest/pkexec.1.html). Windows users +#' must run RStudio as administrator. On macOS and RStudio Server, menu bar styling is not necessary and running this function has no effect. +#' +#' @return Nothing (`NULL` invisibly). #' @export -deactivate_menu_theme <- function(){ - - ## Styling menus not supported on Mac. - if(host_os_is_mac()) return(NULL) +uninstall_menu_theme <- function() { + + ## menu bar styling not supported on Mac + if (is_macos()) return(NULL) + + path_theme_dark_gnome <- path_theme_dark_gnome() + path_theme_dark_gnome_backup <- path_theme_dark_gnome_backup() + path_theme_dark_windows <- path_theme_dark_windows() + path_theme_dark_windows_backup <- path_theme_dark_windows_backup() + is_rscodeio_current_gnome <- is_rscodeio_menu_theme(path_theme_dark_gnome) + is_rscodeio_current_windows <- is_rscodeio_menu_theme(path_theme_dark_windows) + exists_theme_dark_gnome_backup <- fs::file_exists(path_theme_dark_gnome_backup) + exists_theme_dark_windows_backup <- fs::file_exists(path_theme_dark_windows_backup) + + # shouldn't really happen + if (exists_theme_dark_gnome_backup && is_rscodeio_menu_theme(path_theme_dark_gnome_backup)) { + + stop("The following backed up file supposed to be an unmodified RStudio QSS file is actually an rscodeio QSS file:\n", path_theme_dark_gnome_backup, + "\n", "Delete the file if you'd like this error to be gone.\nUsing the R console: fs::file_delete(rscodeio:::path_theme_dark_gnome_backup())", + call. = FALSE) + } + if (exists_theme_dark_windows_backup && is_rscodeio_menu_theme(path_theme_dark_windows_backup)) { - if(!file.exists(gnome_theme_dark_backup()) | - !file.exists(windows_theme_dark_backup())) { - message("RStudio theme backups not found. rscodeio already deactivated?") - return(FALSE) + stop("The following backed up file supposed to be an unmodified RStudio QSS file is actually an rscodeio QSS file:\n", path_theme_dark_windows_backup, "\n", + "Delete the file if you'd like this error to be gone.\nUsing the R console: fs::file_delete(rscodeio:::path_theme_dark_windows_backup())", + call. = FALSE) } - ## restore dark Qt themes - file.copy(from = gnome_theme_dark_backup(), - to = gnome_theme_dark(), - overwrite = TRUE) - file.copy(from = windows_theme_dark_backup(), - to = windows_theme_dark(), - overwrite = TRUE) + process_menu_themes(restore_gnome = exists_theme_dark_gnome_backup && is_rscodeio_current_gnome, + restore_windows = exists_theme_dark_windows_backup && is_rscodeio_current_windows) + + # print instructive warnings if restoral is impossible + if (!exists_theme_dark_gnome_backup && is_rscodeio_current_gnome) { + + warning("Unable to restore default RStudio menu bar styling for GNOME because the corresponding backup file couldn't be found.\n", + "The most convenient way to restore the original file at ", path_theme_dark_gnome, " is to simply update or reinstall RStudio.\n", + "RStudio stable release installers are available at https://rstudio.com/products/rstudio/download/", + call. = FALSE) + } + if (!exists_theme_dark_windows_backup && is_rscodeio_current_windows) { - ## delete backups - unlink(gnome_theme_dark_backup()) - unlink(windows_theme_dark_backup()) + warning("Unable to restore default RStudio menu bar styling for Windows because the corresponding backup file couldn't be found.\n", + "The most convenient way to restore the original file at ", path_theme_dark_windows, " is to simply update or reinstall RStudio.\n", + "RStudio stable release installers are available at https://rstudio.com/products/rstudio/download/", + call. = FALSE) + } + # display message if rscodeio's menu bar styling has already been removed + if (!exists_theme_dark_gnome_backup && !exists_theme_dark_windows_backup) { + if (!is_rscodeio_current_gnome && !is_rscodeio_current_windows) { + message("rscodeio's menu bar styling is already removed.") + } + } } diff --git a/R/utils.R b/R/utils.R index 7ede2d8..45a5d72 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,7 +1,7 @@ -get_stylesheets_location <- function(){ +path_theme_dir <- function() { ## We shouldn't get here on mac - if(host_os_is_mac()) stop("Qss Stylesheets are not used on Mac") + if (is_macos()) stop("QSS Stylesheets are not used on Mac.") rstudio_dirs <- list( pandoc_dir = Sys.getenv("RSTUDIO_PANDOC"), @@ -11,54 +11,175 @@ get_stylesheets_location <- function(){ rmarkdown_mathjax_path = Sys.getenv("RMARKDOWN_MATHJAX_PATH") ) - extract_rstudio_path_parts <- function(path){ - dir_parts <- fs::path_split(path)[[1]] - rstudio_ind <- which(dir_parts %in% c("RStudio","rstudio")) - if(length(rstudio_ind) != 1) return(NULL) + extract_rstudio_path_parts <- function(path) { + dir_parts <- fs::path_split(path)[[1L]] + rstudio_ind <- which(dir_parts %in% c("RStudio", "rstudio")) + if (length(rstudio_ind) != 1L) return(NULL) dir_parts[seq(rstudio_ind)] } potential_paths <- Filter(function(path_parts) { - !is.null(path_parts) && dir.exists(fs::path_join(c(path_parts, - "resources", - "stylesheets"))) - }, - lapply(rstudio_dirs, extract_rstudio_path_parts) + !is.null(path_parts) && dir.exists(fs::path_join(c(path_parts, + "resources", + "stylesheets")))}, + lapply(rstudio_dirs, extract_rstudio_path_parts) ) - if(length(potential_paths) == 0) stop("Could not find location of your RStudio installation.") + if (length(potential_paths) == 0L) { + stop("Unable to determine RStudio installation path.", + call. = FALSE) + } ## return first path that existed - fs::path_join(c(potential_paths[[1]], "resources", "stylesheets")) + fs::path_join(c(potential_paths[[1L]], "resources", "stylesheets")) +} +path_theme_dark_gnome <- function() { + fs::path(path_theme_dir(), "rstudio-gnome-dark.qss") } -gnome_theme_dark <- function() { - fs::path(get_stylesheets_location(),"rstudio-gnome-dark.qss") +path_theme_dark_gnome_backup <- function() { + fs::path(path_theme_dir(), "rstudio-gnome-dark-rscodeio-backup.qss") } -gnome_theme_dark_backup <- function() { - fs::path(get_stylesheets_location(), "rstudio-gnome-dark-rscodeio-backup.qss") +path_theme_dark_windows <- function() { + fs::path(path_theme_dir(), "rstudio-windows-dark.qss") } -windows_theme_dark <- function() { - fs::path(get_stylesheets_location(),"rstudio-windows-dark.qss") +path_theme_dark_windows_backup <- function() { + fs::path(path_theme_dir(), "rstudio-windows-dark-rscodeio-backup.qss") } -windows_theme_dark_backup <- function() { - fs::path(get_stylesheets_location(),"rstudio-windows-dark-rscodeio-backup.qss") +is_macos <- function() { + unname(Sys.info()["sysname"] == "Darwin") } -host_os_is_mac <- function() { - Sys.info()["sysname"] == "Darwin" +is_linux <- function() { + unname(Sys.info()["sysname"] == "Linux") } is_rstudio_server <- function() { rstudioapi::versionInfo()$mode == "server" } -rscodeio_installed <- function() { - !is.null(rstudioapi::getThemes()$rscodeio) || !is.null(rstudioapi::getThemes()$`tomorrow night bright (rscodeio)`) +is_rscodeio_installed <- function() { + !is.null(rstudioapi::getThemes()[["rscodeio"]]) || !is.null(rstudioapi::getThemes()[["tomorrow night bright (rscodeio)"]]) +} + +is_rscodeio_menu_theme <- function(path_theme) { + grepl(x = readLines(con = path_theme, + n = 1L), + pattern = "rscodeio") +} + +installed_rscodeio_editor_themes <- function() { + grep(x = purrr::map_depth(.x = rstudioapi::getThemes(), + .depth = 1L, + .f = purrr::pluck("name")), + pattern = "rscodeio", + value = TRUE) +} + +process_menu_themes <- function(backup_gnome = FALSE, + backup_windows = FALSE, + override_gnome = FALSE, + override_windows = FALSE, + restore_gnome = FALSE, + restore_windows = FALSE) { + + # return early if nothing to do + if (!any(backup_gnome, + backup_windows, + override_gnome, + override_windows, + restore_gnome, + restore_windows)) return(NULL) + + path_theme_dark_gnome <- path_theme_dark_gnome() + path_theme_dark_gnome_backup <- path_theme_dark_gnome_backup() + path_theme_dark_gnome_rscodeio <- fs::path_package(package = "rscodeio", + "resources", "stylesheets", "rstudio-gnome-dark.qss") + path_theme_dark_windows <- path_theme_dark_windows() + path_theme_dark_windows_backup <- path_theme_dark_windows_backup() + path_theme_dark_windows_rscodeio <- fs::path_package(package = "rscodeio", + "resources", "stylesheets", "rstudio-windows-dark.qss") + + ## interactively ask for administrator credentials on Linux + if (is_linux()) { + + cmd_backup_gnome <- glue::glue('sudo cp "{path_theme_dark_gnome}" "{path_theme_dark_gnome_backup}" ; ') + cmd_backup_windows <- glue::glue('sudo cp "{path_theme_dark_windows}" "{path_theme_dark_windows_backup}" ; ') + cmd_override_gnome <- glue::glue('sudo cp "{path_theme_dark_gnome_rscodeio}" "{path_theme_dark_gnome}" ; ') + cmd_override_windows <- glue::glue('sudo cp "{path_theme_dark_windows_rscodeio}" "{path_theme_dark_windows}" ; ') + cmd_restore_gnome <- glue::glue('sudo cp "{path_theme_dark_gnome_backup}" "{path_theme_dark_gnome}" && sudo rm "{path_theme_dark_gnome_backup}" ; ') + cmd_restore_windows <- glue::glue('sudo cp "{path_theme_dark_windows_backup}" "{path_theme_dark_windows}" && sudo rm "{path_theme_dark_windows_backup}" ; ') + + pkexec_cmd_args <- paste0("env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY bash -c '", + if (backup_gnome) cmd_backup_gnome, + if (backup_windows) cmd_backup_windows, + if (override_gnome) cmd_override_gnome, + if (override_windows) cmd_override_windows, + if (restore_gnome) cmd_restore_gnome, + if (restore_windows) cmd_restore_windows, + "'") + + return_code <- system2(command = "pkexec", + args = pkexec_cmd_args) + + # print instructive warnings if something went wrong + if (return_code != 0L) { + + common_warning <- ' of default RStudio menu bar styling failed. As a workaround, you can manually run the following in a shell as root (sudo):\n\n' + + if (backup_gnome) warning('Backup', common_warning, cmd_backup_gnome, call. = FALSE) + if (backup_windows) warning('Backup', common_warning, cmd_backup_windows, call. = FALSE) + if (override_gnome) warning('Installation', common_warning, cmd_override_gnome, call. = FALSE) + if (override_windows) warning('Installation', common_warning, cmd_override_windows, call. = FALSE) + if (restore_gnome) warning('Restoral', common_warning, cmd_restore_gnome, call. = FALSE) + if (restore_windows) warning('Restoral', common_warning, cmd_restore_windows, call. = FALSE) + } + + } else { + ## other OS' like Windows and macOS need RStudio being run as administrator + if (all(fs::file_access(path = c(if (override_gnome || restore_gnome) path_theme_dark_gnome, + if (override_windows || restore_windows) path_theme_dark_windows, + if (backup_gnome || restore_gnome) path_theme_dark_gnome_backup, + if (backup_windows || restore_windows) path_theme_dark_windows_backup, + if (restore_gnome) path_theme_dark_gnome_rscodeio, + if (restore_windows) path_theme_dark_windows_rscodeio), + mode = "write"))) { + + purrr::walk(.x = list(c(path_theme_dark_gnome, path_theme_dark_gnome_backup)[backup_gnome], + c(path_theme_dark_windows, path_theme_dark_windows_backup)[backup_windows], + c(path_theme_dark_gnome_rscodeio, path_theme_dark_gnome)[override_gnome], + c(path_theme_dark_windows_rscodeio, path_theme_dark_gnome)[override_windows], + c(path_theme_dark_gnome_backup, path_theme_dark_gnome)[restore_gnome], + c(path_theme_dark_windows_backup, path_theme_dark_gnome)[restore_windows]), + .f = ~ { + if (length(.x)) { + fs::file_copy(path = .x[1L], + new_path = .x[2L], + overwrite = TRUE) + } + }) + + if (restore_gnome) fs::file_delete(path_theme_dark_gnome_backup) + if (restore_windows) fs::file_delete(path_theme_dark_windows_backup) + + } else { + + begin_warning <- paste("Backup"[backup_gnome || backup_windows], + "Installation"[override_gnome || override_windows], + "Restoral"[restore_gnome || restore_windows], + sep = "/") + + warning(substr(begin_warning, + start = 1L, + stop = nchar(begin_warning) - 1L), + " of default RStudio menu bar styling impossible due to insufficient user rights. RStudio must be run as administrator for this to work.", + call. = FALSE) + } + } } diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..166bd9e --- /dev/null +++ b/README.Rmd @@ -0,0 +1,117 @@ +--- +output: rmarkdown::github_document +--- + +
+
+
+
+
-
-