[R] unserialize form rawConnection possibe?

Saptarshi Guha saptarshi.guha at gmail.com
Wed Nov 17 20:22:37 CET 2010


Hello,

Consider this little function (not concerned about efficiency here)

m=function(r) { a<-serialize(r,NULL); zz<-rawConnection(raw(0),"r+");
writeBin(length(a),zz); c(rawConnectionValue(zz),a)}
a=m(10)

p=rawConnection(a,"r+"); u=readBin(p,"int")
unserialize(p)


Error in unserialize(p) : unknown input format

But isn't p a connectio?From ?unserialize

'unserialize' reads an object (as written by 'serialize') from
     'connection' or a raw vector.

Also, seek(p,where=NA) returns 0 when it should return 5.

I could do unserialize( a[ 5:(5+u)] ) but sticking with the connection
would be nicer.


Cheers
Saptarshi



More information about the R-help mailing list