Change RStudio theme based on time of day

Is there a way to change an RStudio theme based on the time of day? In macOS, the system appearance, as well as the appearance of many apps, changes based on the time of day---it is light during the daytime and dark during the night (so called Dark Mode). It would be awesome to have the same functionality in RStudio. Does anyone know how to achieve this effect?

A quick search showed that there was a somewhat related discussion about this three years ago, but not much seems to have changed since then.

This could be done using a simple switch in your .Rprofile and the rsthemes package:


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

  # 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")
  }, action = "append")
}

For details visit 🔮 rsthemes · Garrick Aden‑Buie.

1 Like

Awesome, thank you so much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.