Package 'serializer'

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

Help Index


Calculate the size of the R object when it is serialized

Description

This function goes through all the motions of serializing an object, but does nothing with the bytes other than to tally the total length.

Usage

calc_serialized_size(robj)

Arguments

robj

R object

Value

number of bytes needed to serialize this object

Examples

calc_serialized_size(mtcars)

Serialize an R object to a connection

Description

Serialize an R object to a connection

Usage

marshall_con(robj, con = NULL)

Arguments

robj

R object

con

connection to write the data to

Value

none

Examples

tmp <- tempfile()
marshall_con(mtcars, con = gzfile(tmp))
unmarshall_con(gzfile(tmp))

Serialize an R object to a connection using an non-API function from R

Description

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.

Usage

marshall_con_illegal(robj, con = NULL)

Arguments

robj

R object

con

connection to write the data to

Value

none

Examples

tmp <- tempfile()
marshall_con_illegal(mtcars, con = gzfile(tmp))
unmarshall_con_illegal(gzfile(tmp))

Serialize an R object to a file

Description

Serialize an R object to a file

Usage

marshall_file(robj, filename)

Arguments

robj

R object

filename

filename

Value

None

Examples

tmp <- tempfile()
marshall_file(head(mtcars), tmp)
unmarshall_file(tmp)

Serialize an R object to a raw vector

Description

Serialize an R object to a raw vector

Usage

marshall_raw(robj)

Arguments

robj

R object

Value

a raw vector containing the serialized data.

Examples

m <- marshall_raw(head(mtcars))
m
unmarshall_raw(m)

Unserialize an R object from a connection

Description

Unserialize an R object from a connection

Usage

unmarshall_con(con)

Arguments

con

A connection from which to read serialized data

Value

Return the unserialized R object

Examples

tmp <- tempfile()
marshall_con(mtcars, con = gzfile(tmp))
unmarshall_con(gzfile(tmp))

Unserialize an R object from a connection using an non-API function from R

Description

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.

Usage

unmarshall_con_illegal(con)

Arguments

con

A connection from which to read serialized data

Value

Return the unserialized R object

Examples

tmp <- tempfile()
marshall_con_illegal(mtcars, con = gzfile(tmp))
unmarshall_con_illegal(gzfile(tmp))

Unserialize an R object from a file

Description

Unserialize an R object from a file

Usage

unmarshall_file(filename)

Arguments

filename

a file containing serialized data

Value

Return the unserialized R object

Examples

tmp <- tempfile()
marshall_file(head(mtcars), tmp)
unmarshall_file(tmp)

Unserialize an R object from a raw vector

Description

Unserialize an R object from a raw vector

Usage

unmarshall_raw(raw_vec)

Arguments

raw_vec

A raw vector containing serialized data

Value

Return the unserialized R object

Examples

m <- marshall_raw(head(mtcars))
m
unmarshall_raw(m)