object_to_string function

Convert R objects to/from strings

Convert R objects to/from strings

Serialise/deserialise an R object into a string. This is a very thin wrapper around the existing R functions serialize and rawToChar. This is useful to encode arbitrary R objects as string to then save in Redis (which expects a string).

object_to_string(obj) string_to_object(str) object_to_bin(obj, xdr = FALSE) bin_to_object(bin)

Arguments

  • obj: An R object to convert into a string

  • str: A string to convert into an R object

  • xdr: Use the big-endian representation? Unlike, serialize this is disabled here by default as it is a bit faster (~ 20

    microsecond roundtrip for a serialization of 100 doubles)

  • bin: A binary vector to convert back to an R object

Examples

s <- object_to_string(1:10) s string_to_object(s) identical(string_to_object(s), 1:10)
  • Maintainer: Rich FitzJohn
  • License: GPL-2
  • Last published: 2023-11-30