Package 'rsthemes'

Title: Full Themes for RStudio v1.2+
Description: A collection of full RStudio themes built using SCSS theme templates. Includes several hand crafted themes in addition to a large collection of base16 themes.
Authors: Garrick Aden-Buie [aut, cre], Eric Hunt [ctb]
Maintainer: Garrick Aden-Buie <[email protected]>
License: MIT + file LICENSE
Version: 0.5.0
Built: 2024-11-07 05:43:02 UTC
Source: https://github.com/gadenbuie/rsthemes

Help Index


Automatically or manually toggle light, dark, or favorite themes

Description

These functions help manage switching between preferred themes. Use set_theme_light() and set_theme_dark() to declare your preferred light/dark themes that can be toggled or selected automatically with use_theme_toggle() or use_theme_auto() or their corresponding RStudio addins. Alternatively, you can create a list of favorite themes with set_theme_favorite(). You can then cycle through this list with use_theme_favorite() or by using the RStudio addin.

Usage

set_theme_light(theme = NULL)

set_theme_dark(theme = NULL)

set_theme_favorite(theme = NULL, append = TRUE)

use_theme_light(quietly = FALSE)

use_theme_dark(quietly = FALSE)

use_theme_rstudio_default(quietly = FALSE)

use_theme_toggle(quietly = FALSE)

use_theme_auto(
  dark_start = NULL,
  dark_end = NULL,
  lat = NULL,
  lon = NULL,
  quietly = FALSE
)

use_theme_favorite(quietly = FALSE)

Arguments

theme

The name of the theme, or NULL to use current theme.

append

[set_theme_favorite] Should the theme be appended to the list of favorite themes? If FALSE, then theme replaces the current list of favorite themes.

quietly

Suppress confirmation messages

dark_start

Start time of dark mode, in 24-hour "HH:MM" format.

dark_end

End time of dark mode, in 24-hour "HH:MM" format.

lat

Latitude of your current location.

lon

Longitude of your current location.

Details

For best results, set your preferred themes in your ⁠~/.Rprofile⁠ using the instructions in the section below.

Functions

  • set_theme_light(): Set default light theme

  • set_theme_dark(): Set default dark theme

  • set_theme_favorite(): Set favorite themes

  • use_theme_light(): Use default light theme

  • use_theme_dark(): Use default dark theme

  • use_theme_rstudio_default(): Use the RStudio default theme (Textmate)

  • use_theme_toggle(): Toggle between dark and light themes

  • use_theme_auto(): Auto switch between dark and light themes

  • use_theme_favorite(): Walk through a list of favorite themes

Set preferred theme in .Rprofile

Add the following to your ⁠~/.Rprofile⁠ (see usethis::edit_r_profile()) to declare your default themes:

if (interactive() && requireNamespace("rsthemes", quietly = TRUE)) {
  # Set preferred themes if not handled elsewhere..
  rsthemes::set_theme_light("One Light {rsthemes}")  # light theme
  rsthemes::set_theme_dark("One Dark {rsthemes}") # dark theme
  rsthemes::set_theme_favorite(c(
    "GitHub {rsthemes}", "Solarized Dark {rsthemes}", "Fairyfloss {rsthemes}"
  ))


  # Whenever the R session restarts inside RStudio...
  setHook("rstudio.sessionInit", function(isNewSession) {
    # Automatically choose the correct theme based on time of day
    rsthemes::use_theme_auto(dark_start = "18:00", dark_end = "6:00")

    # Alternatively use a dynamic solution based on your location
    # rsthemes::use_theme_auto(lat = 50.30, lon = 9.40)

    # Or alternatively use {ipapi} to determine your location automatically
    # rsthemes::use_theme_auto()
  }, action = "append")
}

Note that the fully automated approach will use ip-api.com to look up your current location using your IP address (if the ipapi package is available). If you'd like to use geolocation but without pinging an external server, you can call rsthemes:::geolocate() once to determine your approximate latitude and longitude, which you can provide to use_theme_auto(). Your location coordinates are cached on a per-project basis and only checked once per day (per project).

Here are two other approaches that you can use. Both set the global options that declare the default themes, but rely on you manually calling use_theme_auto() or the Auto Dark/Light addin.

# ~/.Rprofile
rsthemes::set_theme_light("One Light {rsthemes}")
rsthemes::set_theme_dark("One Dark {rsthemes}")
rsthemes::set_theme_favorite(c(
  "GitHub {rsthemes}", "Solarized Dark {rsthemes}", "Fairyfloss {rsthemes}"
))
# ~/.Rprofile
options(
  rsthemes.theme_light = "One Light {rsthemes}",
  rsthemes.theme_dark = "One Dark {rsthemes}"
  rsthemes.theme_favorite = c("GitHub {rsthemes}", "One Light {rsthemes}")
)

RStudio Addins

rsthemes includes five RStudio addins to help you easily switch between light and dark modes. You can set the default dark or light theme to the current theme. You can also toggle between light and dark mode or switch to the automatically chosen light/dark theme based on time of day. You can set a keyboard shortcut to Toggle Dark Mode, Next Favorite Theme, or Auto Choose Dark or Light Theme from the Modify Keyboard Shortcuts... window under the RStudio Tools menu.

rsthemes also includes Use Default RStudio Theme, powered by use_theme_rstudio_default(). This addin and function reverts RStudio back to the default theme, Textmate. This can be useful when teaching or demonstrating RStudio feature when you want RStudio to look like new.


Create a New Theme

Description

Writes the template files required to create a new RStudio theme. In general, arguments with the prefix theme_ refer to global settings for the built theme. Arguments with ui_rstudio_ refer to RStudio chrome such as tabs, scroll bars, search boxes, and tool bars. Arguments starting with ui_ refer to UI elements inside the coding area, such as the cursor, selection highlighting, etc. Arguments starting with code_ refer to code syntax colors and those starting with rmd_ are specific to R Markdown syntax. The arguments naming conventions may not be perfectly consistent (sorry!).

Usage

rstheme(
  theme_name,
  ui_background,
  ui_foreground,
  code_string,
  code_function,
  code_value,
  code_variable,
  code_message,
  ...,
  theme_path = NULL,
  theme_dark = FALSE,
  theme_flat = FALSE,
  theme_palette = NULL,
  theme_as_sass = FALSE,
  theme_apply = TRUE,
  ui_rstudio_background = "darken($ui_background, 2%)",
  ui_rstudio_foreground = "$ui_foreground",
  ui_rstudio_border = "$ui_background",
  rmd_chunk_background = "darken($ui_background, 5%)",
  ui_rstudio_tabs_inactive_background = "lighten($ui_rstudio_background, 2%)",
  ui_rstudio_tabs_inactive_foreground = "transparentize($ui_foreground, 0.4)",
  ui_rstudio_tabs_inactive_hover_background = "$ui_rstudio_tabs_inactive_background",
  ui_rstudio_tabs_active_background = "$rmd_chunk_background",
  ui_rstudio_tabs_active_foreground = "$ui_foreground",
  ui_rstudio_toolbar_background = "$ui_rstudio_tabs_active_background",
  ui_rstudio_toolbar_foreground = "$ui_foreground",
  ui_rstudio_search = "$ui_rstudio_toolbar_background",
  ui_rstudio_scrollbar_background = "transparentize($ui_background, 0.5)",
  ui_rstudio_scrollbar_handle = "$rmd_chunk_background",
  ui_cursor = "#FF0000",
  ui_cursor_normal_mode = "$ui_cursor",
  ui_gutter_foreground = "transparentize($ui_foreground, 0.75)",
  ui_gutter_background = "$ui_background",
  ui_line_active = "transparentize($rmd_chunk_background, 0.6)",
  ui_selection = "transparentize($rmd_chunk_background, 0.6)",
  ui_line_active_selection = "opacify($ui_selection, 1)",
  ui_line_active_gutter = "$ui_background",
  ui_bracket = "transparentize($ui_cursor, 0.6)",
  ui_invisible = "transparentize($ui_foreground, 0.7)",
  ui_indent_guide = "$ui_invisible",
  ui_margin_line = "lighten($ui_selection, 5%)",
  ui_debug_background = "lighten($ui_background, 10%)",
  ui_fold_arrows_foreground = "$ui_cursor",
  ui_fold_arrows_background = "transparentize($ui_fold_arrows_foreground, 0.5)",
  ui_line_find = "$ui_selection",
  ui_console_selection = "$ui_selection",
  ui_completions_background = "$ui_background",
  ui_completions_foreground = "$ui_foreground",
  ui_completions_border = "$ui_bracket",
  ui_completions_selected_background = "$ui_line_active_selection",
  ui_completions_selected_foreground = "$ui_foreground",
  ui_rstudio_job_progress_bar = "opacify($ui_selection, 1)",
  code_comment = "transparentize($ui_foreground, 0.5)",
  code_namespace_font_style = "italic",
  code_reserved = "$code_string",
  code_operator = "$code_value",
  code_bracket = "$code_function",
  code_namespace = "$code_variable",
  code_identifier = "$ui_foreground",
  code_string_background = "inherit",
  code_function_background = "inherit",
  code_value_background = "inherit",
  code_variable_background = "inherit",
  code_message_background = "inherit",
  code_comment_background = "inherit",
  code_reserved_background = "inherit",
  code_operator_background = "inherit",
  code_bracket_background = "inherit",
  code_namespace_background = "inherit",
  code_identifier_background = "inherit",
  code_other = "$code_string",
  rmd_heading_weight = "600",
  rmd_heading_foreground = "$code_string",
  rmd_heading_background = "$code_string_background",
  rmd_chunk_header = "$code_function",
  rmd_chunk_header_background = "$code_function_background",
  rmd_href = "$code_reserved",
  rmd_href_background = "$code_reserved_background"
)

Arguments

theme_name

Name of the theme

ui_background

General background color in RStudio panes, e.g. Source pane.

ui_foreground

General foreground (text) color in RStudio panes

code_string, code_function, code_value, code_variable, code_message

Color of code tokens in R code.

...

Raw SCSS text strings or rstheme partial themes:

theme_path

Path for output theme

theme_dark

TRUE if the theme is a darke theme, FALSE otherwise (default)

theme_flat

Use additional classes to make the theme a "flat" theme. Default is FALSE.

theme_palette

A list of named colors for use in the theme palette. Color names should not include the $ prefix, e.g. red, but can be referenced in any other color-setting variable in rstheme() as ⁠$<color>⁠, e.g. ⁠$red⁠.

theme_as_sass

If TRUE, the theme is returned as an SCSS file. Otherwise, the compiled .rstheme file is returned (default)

theme_apply

If TRUE (default), the theme will be installed and applied immediately.

ui_rstudio_background

Default: ⁠darken($ui_background, 2%)⁠

ui_rstudio_foreground

Default: ⁠$ui_foreground⁠

ui_rstudio_border

Default: ⁠$ui_background⁠

rmd_chunk_background

Default: ⁠darken($ui_background, 5%)⁠

ui_rstudio_tabs_inactive_background

Default: ⁠lighten($ui_rstudio_background, 2%)⁠

ui_rstudio_tabs_inactive_foreground

Default: ⁠transparentize($ui_foreground, 0.4)⁠

ui_rstudio_tabs_inactive_hover_background

Default: ⁠$ui_rstudio_tabs_inactive_background⁠

ui_rstudio_tabs_active_background

Default: ⁠$rmd_chunk_background⁠

ui_rstudio_tabs_active_foreground

Default: ⁠$ui_foreground⁠

ui_rstudio_toolbar_background

Default: ⁠$ui_rstudio_tabs_active_background⁠

ui_rstudio_toolbar_foreground

Default: ⁠$ui_foreground⁠

ui_rstudio_search

Default: ⁠$ui_rstudio_toolbar_background⁠

ui_rstudio_scrollbar_background

Default: ⁠transparentize($ui_background, 0.5)⁠

ui_rstudio_scrollbar_handle

Default: ⁠$rmd_chunk_background⁠

ui_cursor

Default: ⁠#FF0000⁠

ui_cursor_normal_mode

Default: ⁠$ui_cursor⁠

ui_gutter_foreground

Default: ⁠transparentize($ui_foreground, 0.75)⁠

ui_gutter_background

Default: ⁠$ui_background⁠

ui_line_active

Default: ⁠transparentize($rmd_chunk_background, 0.6)⁠

ui_selection

Default: ⁠transparentize($rmd_chunk_background, 0.6)⁠

ui_line_active_selection

Default: ⁠opacify($ui_selection, 1)⁠

ui_line_active_gutter

Default: ⁠$ui_background⁠

ui_bracket

Highlight on paired bracket Default: ⁠transparentize($ui_cursor, 0.6)⁠

ui_invisible

Default: ⁠transparentize($ui_foreground, 0.7)⁠

ui_indent_guide

Default: ⁠$ui_invisible⁠

ui_margin_line

Default: ⁠lighten($ui_selection, 5%)⁠

ui_debug_background

Default: ⁠lighten($ui_background, 10%)⁠

ui_fold_arrows_foreground

Default: ⁠$ui_cursor⁠

ui_fold_arrows_background

Default: ⁠transparentize($ui_fold_arrows_foreground, 0.5)⁠

ui_line_find

Default: ⁠$ui_selection⁠

ui_console_selection

Default: ⁠$ui_selection⁠

ui_completions_background

Default: ⁠$ui_background⁠

ui_completions_foreground

Default: ⁠$ui_foreground⁠

ui_completions_border

Default: ⁠$ui_bracket⁠

ui_completions_selected_background

Default: ⁠$ui_line_active_selection⁠

ui_completions_selected_foreground

Default: ⁠$ui_foreground⁠

ui_rstudio_job_progress_bar

Default: ⁠opacify($ui_selection, 1)⁠

code_comment

Default: ⁠transparentize($ui_foreground, 0.5)⁠

code_namespace_font_style

Default: italic

code_reserved

Default: ⁠$code_string⁠

code_operator

Default: ⁠$code_value⁠

code_bracket

Default: ⁠$code_function⁠

code_namespace

Default: ⁠$code_variable⁠

code_identifier

Default: ⁠$ui_foreground⁠

code_string_background

Default: inherit

code_function_background

Default: inherit

code_value_background

Default: inherit

code_variable_background

Default: inherit

code_message_background

Default: inherit

code_comment_background

Default: inherit

code_reserved_background

Default: inherit

code_operator_background

Default: inherit

code_bracket_background

Default: inherit

code_namespace_background

Default: inherit

code_identifier_background

Default: inherit

code_other

Default: ⁠$code_string⁠

rmd_heading_weight

Default: 600

rmd_heading_foreground

Default: ⁠$code_string⁠

rmd_heading_background

Default: ⁠$code_string_background⁠

rmd_chunk_header

Default: ⁠$code_function⁠

rmd_chunk_header_background

Default: ⁠$code_function_background⁠

rmd_href

Default: ⁠$code_reserved⁠

rmd_href_background

Default: ⁠$code_reserved_background⁠

Value

Returns the CSS or SCSS (if theme_as_sass is TRUE). If theme_path is provided, the CSS or SCSS is written to the file and the source is returned invisibly. If theme_apply is TRUE, the theme is also installed and applied to the current RStudio session.


RStudio Partial Themes

Description

Partial themes for RStudio to be included as desired in rstheme().

Usage

rstheme_command_palette(
  background = "$ui_background",
  search_background = "$ui_command_palette_background",
  border = "$ui_command_palette_background",
  item_background = "$ui_command_palette_background",
  item_color = "$ui_foreground",
  item_hover_background =
    "if($ui_rstudio_is_dark, lighten($ui_command_palette_item_background, 5%), darken($ui_command_palette_item_background, 5%))",
  item_selected_background =
    "if($ui_rstudio_is_dark, lighten($ui_command_palette_item_background, 10%), darken($ui_command_palette_item_background, 10%))"
)

rstheme_rainbow_parentheses(
  ui_paren_0 = "rgb(255, 124, 124)",
  ui_paren_1 = "rgb(255, 187, 0)",
  ui_paren_2 = "#00ff1f",
  ui_paren_3 = "#2bcf2b",
  ui_paren_4 = "lightskyblue",
  ui_paren_5 = "rgb(150, 94, 255)",
  ui_paren_6 = "violet"
)

rstheme_large_tabs()

rstheme_dialog_options(
  background = "$ui_rstudio_background",
  foreground = "$ui_rstudio_foreground",
  border =
    "if($ui_rstudio_is_dark, lighten($ui_rstudio_dialog_background, 5%), darken($ui_rstudio_dialog_background, 5%))",
  selected_background = "$ui_rstudio_dialog_border",
  selected_foreground = "$ui_rstudio_dialog_foreground",
  heading_foreground = "$code_function",
  help_foreground = "$code_value",
  button_foreground = "$ui_rstudio_dialog_foreground",
  button_background = "$ui_rstudio_dialog_background",
  button_border = "$ui_rstudio_dialog_border",
  button_hover_foreground = "lighten($ui_rstudio_dialog_button_foreground, 10%)",
  button_hover_background = "lighten($ui_rstudio_dialog_button_background, 10%)",
  button_hover_border = "$ui_rstudio_dialog_border",
  input_foreground = "$ui_rstudio_dialog_foreground",
  input_background = "$ui_rstudio_dialog_background",
  input_border = "$ui_rstudio_dialog_border",
  checkbox_background = "lighten($ui_rstudio_dialog_background, 5%)",
  checkbox_foreground = "$ui_rstudio_dialog_foreground",
  select_background = "lighten($ui_rstudio_dialog_background, 5%)",
  select_foreground = "$ui_rstudio_dialog_foreground",
  update_packages_foreground =
    "if($ui_rstudio_is_dark, lighten($ui_rstudio_dialog_background, 20%), darken($ui_rstudio_dialog_background, 40%))"
)

rstheme_terminal_colors(
  theme_dark = TRUE,
  red = NULL,
  green = NULL,
  yellow = NULL,
  blue = NULL,
  magenta = NULL,
  cyan = NULL,
  black = if (theme_dark) "darken($ui_background, 5%)" else
    "darken($ui_foreground, 5%)",
  white = if (theme_dark) "darken($ui_foreground, 5%)" else
    "darken($ui_background, 5%)",
  red_bright = red,
  green_bright = green,
  yellow_bright = yellow,
  blue_bright = blue,
  magenta_bright = magenta,
  cyan_bright = cyan,
  black_bright = "mix($terminal_color_black, $terminal_color_white, 40%)",
  white_bright = "lighten($terminal_color_white, 10%)"
)

Arguments

search_background, item_background, item_color, item_hover_background, item_selected_background

Additional color options for the command palette.

border

Border color

ui_paren_0, ui_paren_1, ui_paren_2, ui_paren_3, ui_paren_4, ui_paren_5, ui_paren_6

Parentheses colors 0 through 6.

foreground, background

Foreground (text) or background color

selected_background, selected_foreground, heading_foreground, help_foreground, button_foreground, button_background, button_border, button_hover_foreground, button_hover_background, button_hover_border, input_foreground, input_background, input_border, checkbox_background, checkbox_foreground, select_background, select_foreground, update_packages_foreground

Additional colors for RStudio dialog boxes, setting SCSS variables prefixed with ⁠$ui_rstudio_dialog_<argument>⁠.

theme_dark

Is the theme dark (otherwise light). Used to set the default terminal colors for black and white based on the theme's foreground and background colors.

black, black_bright, red, red_bright, green, green_bright, yellow, yellow_bright, blue, blue_bright, magenta, magenta_bright, cyan, cyan_bright, white, white_bright

Terminal colors, 8 normal and 8 bright.

Functions

  • rstheme_command_palette(): Theme the RStudio Command Palette

  • rstheme_rainbow_parentheses(): Theme the rainbow parentheses colors

  • rstheme_large_tabs(): Enlarges the tabs

  • rstheme_dialog_options(): Themes dialog windows, e.g. Global Options

  • rstheme_terminal_colors(): Theme the terminal colors


Install, List, Try or Remove RStudio Themes

Description

Install, List, Try or Remove RStudio Themes

Usage

install_rsthemes(style = "all", include_base16 = FALSE, destdir = NULL)

remove_rsthemes(style = rsthemes_styles(), include_base16 = TRUE)

list_rsthemes(style = "all", include_base16 = TRUE, list_installed = TRUE)

try_rsthemes(style = "all", include_base16 = TRUE, delay = 0)

rsthemes_styles(..., validate = NULL)

Arguments

style

Limit to a subgroup of themes, chosen from the options returned by rsthemes_styles().

include_base16

Should the base16 themes be included?

destdir

The destination directory for the .rstheme files. By default uses rstudioapi::addTheme() to install themes, but this argument lets users install themes to non-standard directories, or in case the location of the RStudio theme directory has changed.

list_installed

Should the installed rsthemes themes be listed (default). If FALSE, the available themes in the rsthemes package are listed instead.

delay

Number of seconds to wait between themes. Set to 0 to be prompted to continue after each theme.

...

Ignored.

validate

If provided to rsthemes_styles(), checks that the specified style is valid.

Functions

  • install_rsthemes(): Install RStudio themes

  • remove_rsthemes(): Remove rsthemes from RStudio

  • list_rsthemes(): List installed themes (default) or available themes

  • try_rsthemes(): Try each rsthemes RStudio theme

  • rsthemes_styles(): List style options

Palettes

rsthemes includes RStudio themes based on the following colors palettes.