Skip to contents

check lightMode for light background color

Usage

checkLightMode(
  lightMode = getOption("jam.lightMode"),
  positron_default = getOption("jam.lightMode.positron", TRUE),
  html_default = getOption("jam.lightMode.html", TRUE),
  knitr_default = getOption("jam.lightMode.knitr", TRUE),
  other_default = getOption("jam.lightMode.other", FALSE),
  ...
)

Arguments

lightMode

logical or NULL, indicating whether the lightMode parameter has been defined in the function call. The default getOption("jam.lightMode") is NULL unless assigned. When NULL it will use logic described in Details. When assigned, it is used as-is.

positron_default

logical default TRUE, applied only when running inside Positron, and when rstudioapi::getThemeInfo() is not available, which is default for Positron as of jamba-1.0.5. When running inside RStudio, it calls rstudioapi::getThemeInfo() to determine whether the theme is light or dark.

html_default

logical default TRUE, applied when knitr is running with html output.

knitr_default

logical default TRUE, applied when knitr is running.

other_default

logical default FALSE, applied when running outside Positron or RStudio.

...

Additional arguments are ignored.

Value

logical indicating whether lightMode is defined

Details

Check the lightMode status through options('jam.lightMode'), or by determining the running environment.

Logic is applied as follows:

  • When lightMode is defined upfront as logical, it is used.

  • When getOption('jam.lightMode') is defined, it is used.

  • When lightMode is NULL, it will apply a suitable default:

    • If running inside knitr, it will apply html_default for html output, and knitr_default otherwise. Typically both produce white background, however this gives the option for custom background color.

    • If running inside Positron or RStudio, it will attempt to run rstudioapi::getThemeInfo() and use the resulting 'theme$dark', otherwise it applies positron_default.

    • All other cases use other_default, default is FALSE to apply to linux remote shell session with dark background.

To set a persistent default lightMode, add this line to .Rprofile:

  • options("jam.lightMode"=TRUE)

Examples

checkLightMode(FALSE);
#> [1] FALSE
checkLightMode();
#> [1] TRUE