Configure MAIDR interception and display behavior using R's options system.
Available Options
maidr.auto_showLogical. Master switch for all MAIDR interception. When FALSE, all plotting functions behave as standard R. Default: TRUE.
maidr.base_rLogical. Enable Base R plot interception. When TRUE, Base R plots are captured and displayed in the MAIDR viewer, and the ones an R Markdown or Quarto document draws are accessible charts; when FALSE, a document's Base R plots are knitr's static figures (svglite in HTML). Default: TRUE.
maidr.ggplot2Logical. Enable ggplot2 auto-display. When TRUE, ggplot2 objects are automatically rendered in the MAIDR viewer instead of the standard graphics device, and the ones an R Markdown or Quarto document draws are accessible charts; when FALSE, a document's ggplot2 plots are knitr's static figures (svglite in HTML). Default: TRUE.
maidr.latticeLogical. Enable lattice auto-display. When TRUE, a lattice (trellis) object printed at the console to the screen is rendered in the MAIDR viewer, and the ones an R Markdown or Quarto document draws, returned from a chunk or printed in it, are accessible charts. A print into a file device, or one that places the chart on a shared page with
split,positionormore, is drawn by lattice as before. Default: TRUE.maidr.startup_messageLogical. Show startup message when package is loaded. Default: TRUE.
maidr.knitr_devLogical. In an R Markdown or Quarto document rendered to HTML, maidr records the static figures of a chunk with
svgliterather than knitr's defaultpng, so they are vector images like its charts. Only that default is replaced: a device a chunk names (dev = "png"in its header or a#|line) is kept, as is a document device other thanpng, the device of a cached chunk, of an animation (fig.show = "animate") and of a chunk that crops its figures or hands them tofig.process, and that of a chunk in another language than R. The switch starts with the chunk after the one that installs maidr into the document: the chunk that loads maidr, or, in a session that loaded it before the render, the first one that draws a chart or callsmaidr_on(). Set this toFALSE, before the render or in the setup chunk, to keeppngfor every chunk: a document whosepngis a choice,dev: pngin its YAML header or Quarto'sknitr: opts_chunk: dev: png, cannot be told from the default. Charts are inline either way. Default: TRUE.maidr.dotpad_sdk_urlCharacter. URL of a copy of the DotPad tactile-display SDK module (
DotPadSDK-3.0.3.js) that you serve yourself. maidr.js does not bundle the SDK, whose braille engine is a 14 MB liblouis build; unless told otherwise it imports the vendor's copy from jsDelivr the first time a DotPad is connected, from a document rendered withuse_cdn = FALSEas much as any other. Set this to keep that path off the network too. Falls back to the environment variableMAIDR_DOTPAD_SDK_URL. Default: unset.maidr.dotpad_asset_base_urlCharacter. URL of the directory holding the SDK's braille engine (
liblouis.js,.wasm,.data), needed only when it is not thelib/folder beside the module. Falls back to the environment variableMAIDR_DOTPAD_ASSET_BASE_URL. Default: unset.maidr.dotpad_sdk_dirCharacter. Directory where
maidr_download_dotpad_sdk()writes the SDK and whereshow()andsave_html()look for it when a document is rendered withuse_cdn = FALSE. Falls back to the environment variableMAIDR_DOTPAD_SDK_DIR, then to a per-user cache directory. Default: unset.maidr.cdn_versionCharacter. Which MAIDR.js the CDN paths load: a version such as
"4.9.0"(a leadingvis accepted),"bundled"for the version bundled with this package (maidr:::MAIDR_VERSION), or"latest"for jsDelivr's@latesttag. Either tag skips the version lookup described below. Anything else warns once and is ignored. Falls back to the environment variableMAIDR_CDN_VERSION. Default: unset, which loads the latest published version.maidr.cdn_timeoutNumeric. Seconds allowed for the whole CDN version lookup, clamped to between 0.1 and 30. Falls back to the environment variable
MAIDR_CDN_TIMEOUT. Default: 3.maidr.locale_base_urlCharacter, or
FALSE. Where maidr.js fetches a language other than English from, in the documents that load the bundled maidr.js (see the section on languages below): a directory URL to serve the locale packs yourself, or""orFALSEto declare nothing, which keeps such a document off the network and in English. A URL set here is declared in CDN documents too. Falls back to the environment variableMAIDR_LOCALE_BASE_URL. Default: unset, which declares the packs of the bundled version on jsDelivr.
Setting Options
Options can be set in your .Rprofile to persist across sessions:
# Disable ggplot2 interception by default
options(maidr.ggplot2 = FALSE)
# Draw printed lattice charts with lattice, as without maidr
options(maidr.lattice = FALSE)
# Disable all interception
options(maidr.auto_show = FALSE)
# Suppress startup message
options(maidr.startup_message = FALSE)
# Keep knitr's png for the static figures of an R Markdown or Quarto page
options(maidr.knitr_dev = FALSE)
# Serve the DotPad SDK from your own server instead of jsDelivr
options(
maidr.dotpad_sdk_url = "https://example.org/vendor/DotPadSDK-3.0.3.js",
maidr.dotpad_asset_base_url = "https://example.org/vendor/lib/"
)
# Serve MAIDR's language packs yourself, or never fetch one (English only)
options(maidr.locale_base_url = "https://example.org/maidr/")
options(maidr.locale_base_url = FALSE)DotPad SDK and offline documents
The two maidr.dotpad_*_url options are written into every document
this package produces (show(), save_html(), the htmlwidget,
knitr and Shiny) as the globals window.MAIDR_DOTPAD_SDK_URL and
window.MAIDR_DOTPAD_ASSET_BASE_URL, ahead of maidr.js, which
reads them when a DotPad is connected. Nothing is written when neither is
set. Without them a DotPad needs network access to jsDelivr on first
connect, even from a use_cdn = FALSE document; the rest of the
document works offline either way.
The other way to keep a DotPad off the network is to download the SDK
once with maidr_download_dotpad_sdk(): show() and
save_html() then copy it into lib/dotpad-sdk-<version>/ beside
every use_cdn = FALSE document and declare the globals with that
relative path. A configured URL wins over a downloaded copy. The widget
and Shiny paths render their charts in srcdoc frames, where a
relative path has nothing to resolve against, and a knitted document does
not carry the downloaded copy, so they use only the URL options.
Languages other than English
MAIDR.js reads a chart in English on its own, and in Korean, Japanese,
Chinese, Spanish, German, French, Italian or Hindi from a locale pack,
locale-<code>.js, that it fetches from beside itself when the
reader's language is chosen or detected. A document that loads MAIDR.js
from the CDN finds the packs there. This package does not bundle them –
they would add 0.8 MB to an installed package already over CRAN's size
guideline – so every document that loads the bundled MAIDR.js, from
lib/ or inlined, declares window.maidrLocaleBaseUrl ahead of
it: the packs of the bundled version on jsDelivr, unless
maidr.locale_base_url names another place or none. English needs no
network; another language is fetched when the reader is online and stays
English when they are not. A page that declares
window.maidrLocaleBaseUrl itself keeps its own.
Which MAIDR.js the CDN serves
Documents that load MAIDR.js from the jsDelivr CDN – show() and
save_html() with use_cdn = TRUE, and the widget and Shiny
paths when they find the machine online – load the latest published
MAIDR.js, as the Python binding does. Documents rendered with
use_cdn = FALSE load the copy bundled with this package, and reach
the network only for the two things described above: a DotPad's SDK and
a language other than English. So does a knitted R Markdown or Quarto
page, which loads the bundled copy once for all its charts; only the
charts kept in frames of their own, in outputs such as an HTML fragment
or pagedown, load the CDN copy when the machine is online.
The first CDN document in an R session asks which version is the latest:
jsDelivr's data API
(https://data.jsdelivr.com/v1/packages/npm/maidr/resolved?specifier=latest),
then the npm registry
(https://registry.npmjs.org/-/package/maidr/dist-tags) if that
fails, within maidr.cdn_timeout seconds for the two together. The
answer is kept for the rest of the session, and the document names that
version, which never changes under the reader. When neither answers –
offline, blocked, timed out – that too is kept, no error is raised, and
the document names the version bundled with this package, the copy
use_cdn = FALSE would serve, as the Python binding does. So does
an answer older than the bundled version. The mutable maidr@latest
tag, which jsDelivr caches for up to a week, is used only when
maidr.cdn_version = "latest" asks for it.
Pin a version when a document has to load the same MAIDR.js wherever and whenever it is opened, or to keep the one this package was tested with: