Last active
May 15, 2024 15:41
-
-
Save mine-cetinkaya-rundel/465335e8ff4d0e8beb38b296a6ac712d to your computer and use it in GitHub Desktop.
Add to your .Rprofile to change RStudio theme based on hour of the day (dark mode 8pm-6am, light mode 7am-7pm)
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
# theme options based on hour of day ------------------------------------------- | |
# based on https://github.com/rstudio/rstudio/issues/1579 | |
setHook("rstudio.sessionInit", function(chooseTheme) { | |
if (chooseTheme) { | |
if (as.numeric(format(as.POSIXct(Sys.time(), format = "%H:%M:%S"), "%H")) %in% c(0:5, 21:23)) { | |
if (rstudioapi::getThemeInfo()$editor != "Solarized Dark") rstudioapi::applyTheme("Solarized Dark") | |
} else { | |
if (rstudioapi::getThemeInfo()$editor != "Solarized Light") rstudioapi::applyTheme("Solarized Light") | |
} | |
} | |
}, | |
action = "replace" | |
) |
Thank you very much.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sbalci Wrapping it in
as.numeric()
converts it to numeric, without the leading 0: