Title: | Expose R's Serialization Interface |
---|---|
Description: | Expose R's serialization interface for serialing/unserializing R objects to/from raw vectors and connections. |
Authors: | Mike Cheng [aut, cre, cph], Henrik Bengtsson [ctb] |
Maintainer: | Mike Cheng <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.2 |
Built: | 2024-11-01 11:16:08 UTC |
Source: | https://github.com/coolbutuseless/serializer |
This function goes through all the motions of serializing an object, but does nothing with the bytes other than to tally the total length.
calc_serialized_size(robj)
calc_serialized_size(robj)
robj |
R object |
number of bytes needed to serialize this object
calc_serialized_size(mtcars)
calc_serialized_size(mtcars)
Serialize an R object to a connection
marshall_con(robj, con = NULL)
marshall_con(robj, con = NULL)
robj |
R object |
con |
connection to write the data to |
none
tmp <- tempfile() marshall_con(mtcars, con = gzfile(tmp)) unmarshall_con(gzfile(tmp))
tmp <- tempfile() marshall_con(mtcars, con = gzfile(tmp)) unmarshall_con(gzfile(tmp))
This approach will not pass R CMD check
as the function 'R_WriteConnection()'
is not part of the R API, but it is much much faster than the officially
blessed method of calling-back-into-R to write to a connection.
marshall_con_illegal(robj, con = NULL)
marshall_con_illegal(robj, con = NULL)
robj |
R object |
con |
connection to write the data to |
none
tmp <- tempfile() marshall_con_illegal(mtcars, con = gzfile(tmp)) unmarshall_con_illegal(gzfile(tmp))
tmp <- tempfile() marshall_con_illegal(mtcars, con = gzfile(tmp)) unmarshall_con_illegal(gzfile(tmp))
Serialize an R object to a file
marshall_file(robj, filename)
marshall_file(robj, filename)
robj |
R object |
filename |
filename |
None
tmp <- tempfile() marshall_file(head(mtcars), tmp) unmarshall_file(tmp)
tmp <- tempfile() marshall_file(head(mtcars), tmp) unmarshall_file(tmp)
Serialize an R object to a raw vector
marshall_raw(robj)
marshall_raw(robj)
robj |
R object |
a raw vector containing the serialized data.
m <- marshall_raw(head(mtcars)) m unmarshall_raw(m)
m <- marshall_raw(head(mtcars)) m unmarshall_raw(m)
Unserialize an R object from a connection
unmarshall_con(con)
unmarshall_con(con)
con |
A connection from which to read serialized data |
Return the unserialized R object
tmp <- tempfile() marshall_con(mtcars, con = gzfile(tmp)) unmarshall_con(gzfile(tmp))
tmp <- tempfile() marshall_con(mtcars, con = gzfile(tmp)) unmarshall_con(gzfile(tmp))
This approach will not pass R CMD check
as the function 'R_ReadConnection()'
is not part of the R API, but it is much much faster than the officially
blessed method of calling-back-into-R to read from a connection.
unmarshall_con_illegal(con)
unmarshall_con_illegal(con)
con |
A connection from which to read serialized data |
Return the unserialized R object
tmp <- tempfile() marshall_con_illegal(mtcars, con = gzfile(tmp)) unmarshall_con_illegal(gzfile(tmp))
tmp <- tempfile() marshall_con_illegal(mtcars, con = gzfile(tmp)) unmarshall_con_illegal(gzfile(tmp))
Unserialize an R object from a file
unmarshall_file(filename)
unmarshall_file(filename)
filename |
a file containing serialized data |
Return the unserialized R object
tmp <- tempfile() marshall_file(head(mtcars), tmp) unmarshall_file(tmp)
tmp <- tempfile() marshall_file(head(mtcars), tmp) unmarshall_file(tmp)
Unserialize an R object from a raw vector
unmarshall_raw(raw_vec)
unmarshall_raw(raw_vec)
raw_vec |
A raw vector containing serialized data |
Return the unserialized R object
m <- marshall_raw(head(mtcars)) m unmarshall_raw(m)
m <- marshall_raw(head(mtcars)) m unmarshall_raw(m)