pkgdown/mathjax-config.html

Skip to contents

Allows advanced users to define their own validation step without growing the package's built-in API surface. The step function receives (value, name, ctx) and should call fail() on validation failure.

Usage

require_custom(restriction, label, fn, deps = character(0L))

Arguments

restriction

a restriction object.

label

character(1) human-readable description for printing.

fn

a function with signature function(value, name, ctx) that calls fail() on validation failure.

deps

character vector of context names this step requires (default: none).

Value

A new restriction object with the custom step appended.

Examples

# Custom step: require all values to be unique
require_unique_id <- restrict("id") |>
  require_custom(
    label = "must contain unique values",
    fn = function(value, name, ctx) {
      dupes <- which(duplicated(value))
      if (length(dupes) > 0L) {
        fail(name, "contains duplicates", at = dupes)
      }
    }
  )