getStructField: Access a native structure from R

getStructFieldR Documentation

Access a native structure from R

Description

These functions allow one to access a compiled/native struct object from within R based on the description of its fields. We can copy the entire structure or access individual fields using the two functions.

Usage

getStructField(ptr, id, type)
getStructValue(ptr,type)

Arguments

ptr

the reference to the native object. This should be an external pointer or coercable to one.

id

the name or index of the field of the structure to be accessed

type

the FFIType describing the struct's fields

Value

getStructValue returns a list with the copies of the values of the fields. If names are available from the type description, these are used as the names of the list.

getStructField returns the individual R equivalent of the current value of the corresponding field.

Author(s)

Duncan Temple Lang

See Also

structType

Examples

  ptr = getNativeSymbolInfo("globalStruct")$address
  myStruct.type = structType(list(s = sint16Type, i = sint32Type, d = doubleType, str = stringType))
  getStructValue(ptr, myStruct.type)
  getStructField(ptr, 2, myStruct.type)
  getStructField(ptr, "i", myStruct.type)

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