| Title: | Extension to R Serialization |
|---|---|
| Description: | Extends the functionality of R serialization by augmenting the built-in reference hook system. This enhanced implementation allows an integrated single-pass operation that combines R serialization with third-party serialization methods. Facilitates the serialization of even complex R objects, which contain non-system reference objects, such as those accessed via external pointers, to enable their use in parallel and distributed computing. |
| Authors: | Charlie Gao [aut, cre] (ORCID: <https://orcid.org/0000-0002-0750-061X>), Travers Ching [aut] |
| Maintainer: | Charlie Gao <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-05-13 08:44:59 UTC |
| Source: | https://github.com/rconsortium/sakura |
Extends the functionality of R serialization by augmenting the built-in reference hook system. This enhanced implementation allows an integrated single-pass operation that combines R serialization with third-party serialization methods. Facilitates the serialization of even complex R objects, which contain non-system reference objects, such as those accessed via external pointers, to enable their use in parallel and distributed computing.
Maintainer: Charlie Gao [email protected] (ORCID)
Authors:
Travers Ching [email protected]
Useful links:
Report bugs at https://github.com/shikokuchuo/sakura/issues
Returns a serialization configuration for custom serialization and unserialization of non-system reference objects, using the 'refhook' system of R native serialization. This allows their use across different R sessions.
serial_config(class, sfunc, ufunc)serial_config(class, sfunc, ufunc)
class |
a character string (or vector) of the class of object custom
serialization functions are applied to, e.g. |
sfunc |
a function (or list of functions) that accepts a reference
object inheriting from |
ufunc |
a function (or list of functions) that accepts a raw vector and returns a reference object. |
A list comprising the configuration. This may be provided to the
hook argument of serialize() and unserialize().
serial_config("test_class", base::serialize, base::unserialize) serial_config( c("class_one", "class_two"), list(base::serialize, base::serialize), list(base::unserialize, base::unserialize) )serial_config("test_class", base::serialize, base::unserialize) serial_config( c("class_one", "class_two"), list(base::serialize, base::serialize), list(base::unserialize, base::unserialize) )
An extension of R native serialization using the 'refhook' system for custom serialization and unserialization of non-system reference objects.
serialize(x, hook = NULL) unserialize(x, hook = NULL)serialize(x, hook = NULL) unserialize(x, hook = NULL)
x |
an object. |
hook |
[default NULL] optionally, a configuration returned by
|
For serialize: a raw vector. For unserialize: the unserialized object.
vec <- serialize(data.frame()) vec unserialize(vec) obj <- list(arrow::as_arrow_table(iris), arrow::as_arrow_table(mtcars)) cfg <- serial_config( "ArrowTabular", arrow::write_to_raw, function(x) arrow::read_ipc_stream(x, as_data_frame = FALSE) ) raw <- serialize(obj, cfg) unserialize(raw, cfg) x <- list(torch::torch_rand(5L), runif(5L)) cfg <- serial_config("torch_tensor", torch::torch_serialize, torch::torch_load) unserialize(serialize(x, cfg), cfg) cfg <- serial_config( c("torch_tensor", "ArrowTabular"), list(torch::torch_serialize, arrow::write_to_raw), list(torch::torch_load, function(x) arrow::read_ipc_stream(x, as_data_frame = FALSE)) ) y <- list(torch::torch_rand(5L), runif(5L), arrow::as_arrow_table(iris)) unserialize(serialize(y, cfg), cfg)vec <- serialize(data.frame()) vec unserialize(vec) obj <- list(arrow::as_arrow_table(iris), arrow::as_arrow_table(mtcars)) cfg <- serial_config( "ArrowTabular", arrow::write_to_raw, function(x) arrow::read_ipc_stream(x, as_data_frame = FALSE) ) raw <- serialize(obj, cfg) unserialize(raw, cfg) x <- list(torch::torch_rand(5L), runif(5L)) cfg <- serial_config("torch_tensor", torch::torch_serialize, torch::torch_load) unserialize(serialize(x, cfg), cfg) cfg <- serial_config( c("torch_tensor", "ArrowTabular"), list(torch::torch_serialize, arrow::write_to_raw), list(torch::torch_load, function(x) arrow::read_ipc_stream(x, as_data_frame = FALSE)) ) y <- list(torch::torch_rand(5L), runif(5L), arrow::as_arrow_table(iris)) unserialize(serialize(y, cfg), cfg)