# install.packages("devtools")
::install_github("gadenbuie/rsthemes")
devtools# or
install.packages(
"rsthemes",
repos = c(gadenbuie = 'https://gadenbuie.r-universe.dev', getOption("repos"))
# but this package is not updated to the newest version of R so stronly recommends installment from github )
As is known that there are multiple themes for RStudio, I have used the light theme for a long time since I code most of the time during the day. Yet, yesterday at 1am when I switched between Github(with Night Mode) and RStudio, my eyes were crying. Below is what I figured out to make RStudio alternate between light and dark themes according to the time.
The basic idea is preparing a list of themes to be used and setting options and environmental variables for your RStudio.
Step 1
Install rsthemes
package and a dozen of themes.
Then, install themes for use.
::install_rsthemes()
rsthemes# list installed themes
::list_rsthemes()
rsthemes# try all themes
::try_rsthemes() rsthemes
Step 2
Edit your .Rprofile
via this usethis::edit_r_profile()
within a R session in RStudio. Then, your .Rprofile
will pop up in source panel of RStudio. Copy this (below) and save. You can customize your preferred themes and the time to switch to night mode and back.
if (interactive() && requireNamespace("rsthemes", quietly = TRUE)) {
# Set preferred themes if not handled elsewhere..
::set_theme_light("One Light {rsthemes}") # light theme
rsthemes::set_theme_dark("One Dark {rsthemes}") # dark theme
rsthemes
# Whenever the R session restarts inside RStudio...
setHook("rstudio.sessionInit", function(isNewSession) {
# Automatically choose the correct theme based on time of day
::use_theme_auto(dark_start = "18:00", dark_end = "6:00")
rsthemesaction = "append")
}, }
Restart R and done. The awkward thing is that the switch works only when you restart your R session but anyway easier than switching themes manually.
You can refer to these for details, change RStudio theme based on time of day and manage R with .Rprofile.