Some packages want schemate functionality without taking
a runtime dependency on schemate. For that use case, the
project publishes a generated standalone bundle on the
standalone branch.
Import
Run this from the target package:
usethis::use_standalone("hongyuanjia/schemate", "schema", ref = "standalone")The imported file contains the same core schema_ API
used by the package: schema_infer(), the edit helpers,
schema_write(), schema_read(), and
schema_validate().
The target package must still declare the standalone imports. Core
schema inference, editing, printing, and validation need
checkmate and S7. schema_read()
and schema_write() use jsonlite at runtime, so
packages that call those functions should list jsonlite in
Suggests or Imports.
When jsonlite is not installed, JSON IO fails with an
installation hint. Printing still works through a small base R
fallback.
Register S7 classes and methods
Next, create a .onLoad() in zzz.R that
calls S7::methods_register():
.onLoad <- function(libname, pkgname) {
S7::methods_register()
}This is S7’s way of registering methods.