Call vecvec_register() inside your package's .onLoad() function to register the S3 methods that allow a custom vecvec subclass to participate in the vctrs vector system.

vecvec_register(
  x,
  f_ptype2 = vec_ptype2_vecvec,
  f_cast_to = vec_cast_to_vecvec,
  f_cast_from = vec_cast_from_vecvec
)

Arguments

x

An S7 class object that extends class_vecvec. Typically the class object created by S7::new_class() in your package, e.g. class_myvec.

f_ptype2

The function to register as the vec_ptype2 method for this class. Defaults to vec_ptype2_vecvec, guarantees that the common type of two vectors is a vecvec vector.

f_cast_to

The function to register as the vec_cast.<class>.* methods for this class. Defaults to vec_cast_to_vecvec, which attempts to cast other types to vecvec by calling vecvec().

f_cast_from

The function to register as the vec_cast.*.<class> methods for this class. Defaults to vec_cast_from_vecvec, which attempts to cast vecvec to other types by calling unvecvec().

Value

NULL, invisibly. Called for its side effects.

Details

Specifically, vecvec_register() registers:

  • vec_cast.<class>.* methods, so that other types can be cast to your vecvec subclass.

  • vec_cast.*.<class> methods, so that your vecvec subclass can be cast from other types.

Examples

if (FALSE) { # \dontrun{
# In your package, define a vecvec subclass:
class_myvec <- S7::new_class(
  "myvec",
  parent = vecvec::class_vecvec
)

# Then register it in .onLoad():
.onLoad <- function(libname, pkgname) {
  S7::methods_register()
  vecvec::vecvec_register(class_myvec)
}
} # }