Skip to contents

Returns an external pointer to the SEXP (R object header) while ensuring the object won't be garbage collected as long as the pointer exists.

Usage

sexp_ptr(x)

Arguments

x

Any R object

Value

External pointer to the SEXP, with finalizer to release protection

Examples

if (FALSE) { # \dontrun{
x <- c(1L, 2L, 3L) # Use c() not 1:3 to avoid ALTREP
ptr <- sexp_ptr(x)
# ptr is now safe to pass to C functions expecting SEXP
# When ptr is garbage collected, the protection is released
} # }