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:
Hello,

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:

   writeBin(object=binary,con="fileName.txt")

Then eventually if I want to use it in R I just load it:

   load("fileName.txt")

However, how can I go from the binary directly into an Robject without writing 
it to a file?

   say:

   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,

Ramiro

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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,                  rip...@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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to