Last active
November 14, 2016 14:06
-
-
Save talegari/b2477dbcc8dd376b66ec273d6b9c77cc to your computer and use it in GitHub Desktop.
encode/decode R objects as/from strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
# | |
# 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