Skip to main content

emit_s3_generic_guard

Function emit_s3_generic_guard 

Source
pub(crate) fn emit_s3_generic_guard(name: &str) -> String
Expand description

Emit the conditional S3 generic guard for a given generic name.

Returns an R code string (to be pushed onto a lines: Vec<String> with lines.push(emit_s3_generic_guard(name))) that creates the generic only when it doesn’t already exist as a function:

if (!exists("name", mode = "function")) {
  name <- function(x, ...) UseMethod("name")
}

Use this for S3/vctrs class generators and trait-ABI wrappers. Do not use for S7 generics — those use S7::new_generic() / S7::new_external_generic().