Serialization from the C API for R