Skip to content
Prev 59924 / 63424 Next

[External] SET_COMPLEX_ELT and SET_RAW_ELT missing from Rinternals.h

On Thu, 1 Jul 2021, Konrad Siek wrote:

            
The first question is whether you need to do this. Or, more to the
point, whether it is safe to do this. In R objects should behave as if
they are not mutable. Mutation in C code may be OK if the objects are
not reachable from any R variables, but that almost always means they
are private to your code so yo can use what you know about internal
structure.

If it is legitimate to mutate you can use SET_COMPLEX_ELT. I've added
the declaration to Rinternals in R-devel and R-patched.

For SET_COMPLEX_ELT(x, in v) is equivalent to COMPLEX(sexp)[index] = value,
but that could change in the future it Set methods are supported.

This does materialize a potentially compact object, but again the most
important question is whether mutation is legitimate at all.
COMPLEX0 is not in the API; it will probably be removed from the
installed header files as we clean these up.
ALTCOMPLEX_SET_ELT is an internal implementation feature and not in the API.
Again, it will probably be removed from the installed headers.

Best,

luke