Skip to content

Instantly share code, notes, and snippets.

@talegari
Last active November 14, 2016 14:06
Show Gist options
  • Save talegari/b2477dbcc8dd376b66ec273d6b9c77cc to your computer and use it in GitHub Desktop.
Save talegari/b2477dbcc8dd376b66ec273d6b9c77cc to your computer and use it in GitHub Desktop.
encode/decode R objects as/from strings
###############################################################################
#
# rString ----
#
###############################################################################
#
# author : Srikanth KS (talegari)
# license : GNU AGPLv3 (http://choosealicense.com/licenses/agpl-3.0/)
#
###############################################################################
#
# Description ----
#
# ro_string: encodes an R object as a string
# string_ro: decodes a string encodes by `ro_string` to the R object
#
# Depends ----
#
# `base64enc` package and `R(>=3)`
ro_string <- function(obj){
base64enc::base64encode(serialize(obj, connection = NULL))
}
string_ro <- function(string){
unserialize(base64enc::base64decode(string))
}
# # example
# temp <- iris
# ro_string(temp)
# string_ro(ro_string(temp))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment