setSlots: Run-time helper function to set slots of an object by name

View source: R/setSlots.R

setSlotsR Documentation

Run-time helper function to set slots of an object by name

Description

This function is used by some of the programmatically generated to fill in slots in an R object. The main use is when copying fields in a reference to a structure into an R object with slots paralleling the fields in the struct. This occurs in the coercion method from an external pointer to an R class paralleling the C-level struct.

Usage

setSlots(els, obj)

Arguments

els

a named list of the elements to be copied into the corresponding slots

obj

the R object to be populated and assumed to have the appropriate slots

Value

obj, with the relevant slots assigned values from els

Author(s)

Duncan Temple Lang

See Also

The package RGCCTUFFI (https://github.com/omegahat/RGCCTUFFI) has a related defStructClass function.

Examples

  setClass("foo", representation(a = "integer",
                                 b = "character",
                                 d = "data.frame"))

  i = new("foo")
  i = setSlots(list(b = "a string", d = mtcars), i)

  i = setSlots(list(a = 10L), i)

omegahat/Rffi documentation built on Nov. 29, 2023, 12:48 a.m.