s3normalize: Convert a possibly non-serializable R object to a...

Description Usage Arguments Details Value

View source: R/s3normalize.R

Description

R has good foreign function interface bindings to C code. As such, certain package authors may wish to optimize their code by keeping their objects in C structures instead of R SEXPs (the standard for object representation in the R interpreter). This also applies to bindings to external libraries. The speed advantage can be substantial, so this is not an uncommon use case. The s3normalize helper provides the ability to add an additional "preprocessor" layer prior to storing an object to S3 that converts a non-serializable object (such as a list with one of its entries pointing to an external C structure) to serialize object (such as that list with its C structure pointer entry replaced by a raw vector).

Usage

1
s3normalize(object, read = TRUE)

Arguments

object

ANY. The R object to normalize. If it has an "s3mpi.serialize" attribute consisting of a list with "read" and "write" keys, these arity-1 functions will be called with the object prior to reading from and writing to S3, respectively.

read

logical. If TRUE, the "read" key of the "s3mpi.serialize" attribute, which should be a 1-argument function, will be invoked on the object. Otherwise, the "write" key will be invoked. By default, read is TRUE.

Details

If the object being uploaded with s3store or downloaded wiht s3read has an attribute "s3mpi.serialize" which must be a list with keys c("read", "write"), these keys should hold functions requiring a single argument which are applied to the object prior to reading from (s3read) and writing to (s3store) S3, respectively. This allows s3mpi storage of not only vanilla R objects but arbitrary objects in memory (whether they are internally represented by a C, Rust, Java, etc. process).

Value

A previously possibly non-vanilla R object (that is, an R object that may contain external pointers to non-R objects, such as vanilla C structs) converted to a totally vanilla R object (for example, by replacing the pointers with raw binary data).


robertzk/s3mpi documentation built on May 27, 2019, 11:37 a.m.