[R] binary to R object
ramiro at precisionbioassay.com
Wed Jul 30 22:22:33 CEST 2014
rawConnection did it!!
Thank you very much!!!
From: Prof Brian Ripley [ripley at stats.ox.ac.uk]
Sent: Wednesday, July 30, 2014 4:14 PM
To: Ramiro Barrantes; r-help at r-project.org
Subject: Re: [R] binary to R object
What type actually is 'binary' here? We cannot tell, as writeBin will
handle many types.
If 'binary' means a raw vector, two ways:
1) Use load() on a raw connection (see ?rawConnection).
2) Make use of the information in ?readRDS. You can read the header
from save() format by skipping the first 5 bytes, then call
unserialize() on the rest of the raw vector. (If the save was
compressed, you need to handle decompression too: see ?memCompress.)
If you want more help, heed the footer of this and every R-help message
and provide a complete reproducible example.
On 30/07/2014 20:56, Ramiro Barrantes wrote:
> I have stored R objects as hexadecimals in a mysql database, I then usually transform them to binary and then save it into a file. E.g.
> hex <- getBlob #gets blob from database as hexadecimal
> binary <- transformToBinary(hex) #moves from hex to binary
> I would usually save them into a file as follows:
> Then eventually if I want to use it in R I just load it:
> However, how can I go from the binary directly into an Robject without writing it to a file?
> myObject <- unknownFunction(binary)
> I hope this is enough detail. Any help appreciated.
> In retrospect, I could have probably used serialize/unserialize and store a serialize string in mysql and unserialize when needed ( or write to a file if necessary), but I didn't know of those when I did this.
> Thanks in advance,
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help