inst/doc/strict.R

## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  results = "hide"
)

styler::cache_deactivate()

knitr::knit_engines$set(list(
  styler = function(options) {
    options$comment <- ""
    knitr::engine_output(
      options,
      {
        before <- options$code
        after <- as.character(styler::style_text(options$code, strict = FALSE))
        if (!identical(trimws(before, "right"), after)) {
          stop(
            "Before unlike after. Before:", paste(before, sep = "\n"),
            "After: ", paste(after, sep = "\n")
          )
        }
        after
      },
      ""
    )
  }
))

## ----setup--------------------------------------------------------------------
library(styler)

Try the styler package in your browser

Any scripts or data that you put into this service are public.

styler documentation built on Aug. 29, 2023, 5:10 p.m.