Expand description
R6 class wrapper generator (R6Class with $new(), active bindings, private methods).
R6-class R wrapper generator.
Generates an R6::R6Class(...) definition with mutable, reference
semantics: obj$method() dispatches via R6, and &mut self methods
modify state in place without re-binding obj. Supports private methods,
active bindings (computed/settable properties), lifecycle hooks
(finalize, deep_clone), and inheritance via r6(inherit = ...).
Slower than env (R6 dispatch chain) and requires the R6 package; no value
semantics — for value-semantics formal OOP, use S7.
§Emission shape ($set() form, #369)
roxygen2 8.0.0 documents R6 methods added after class creation via
Class$set("public"/"active", "name", function(...) {...}) from the roxygen
block directly preceding the $set call. We emit a minimal R6Class core
(only initialize inline in public, plus the private list) followed by one
$set block per public method and per active binding, each carrying its own
#' roxygen block:
ClassName <- R6::R6Class("ClassName",
public = list(initialize = function(...) { ... }),
private = list(.ptr = NULL),
lock_objects = TRUE, lock_class = FALSE, cloneable = FALSE
)
#' @description <method doc>
#' @param x <param doc>
ClassName$set("public", "method_name", function(x) { ... })
#' @field binding_name <binding doc>
ClassName$set("active", "binding_name", function(value) { ... })initialize stays inline (R6Class needs a well-formed core; its $new doc
stays on the class page). Private methods, finalize, deep_clone, and the
.ptr field stay inline in the private list. The $set calls are part of
the same wrapper fragment string as the class definition, so their ordering
after the class is inherent.
Because R6’s $set() refuses to modify a locked class, the generator always
creates the class with lock_class = FALSE and, when the user asked for
lock_class = TRUE, re-locks it with ClassName$lock() after every $set
(including sidecar accessors) has run. The observable semantics are identical
to a class born locked — the unlocked window is confined to package load.
Constants§
- MX_
INHERITED_ 🔒PARAM_ PREFIX - Marker prefix emitted by the proc-macro when a subclass method param might be
inherited from a parent class documented in-package. Resolved at write-time in
registry.rsto either nothing (parent is documented → roxygen2 inherits) or(no documentation available)(parent not found or not in-package).
Functions§
- active_
setter_ 🔒precondition_ checks - Build the
stopifnot()precondition lines for the setter branch of a combined getter/setter active binding. - generate_
r6_ r_ wrapper - Generates the complete R wrapper string for an R6-style class.