Problem with serialization via readRDS() on a textConnection()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem with serialization via readRDS() on a textConnection()

Christopher Walker
Hi All,

I had working code under R v3.2 that serialized an object, stored the
serialized object in a database, and then successfully retrieved and
hydrated that object.

I recently updated to R v3.4.1 and the same code now fails.

Here is the code in question (simplified), and the resulting error:


> zz = textConnection('tempConnection', 'wb')
> saveRDS(c("a", "b", "c"), zz, ascii = TRUE)
> serialized_obj = paste(textConnectionValue(zz), collapse='\n')
> readRDS(textConnection(serialized_obj))
Error in gzcon(file) : 'read' not enabled for this connection


Docs haven't been much help in this case. I've tried a number of variations
but no luck. readRDS() was updated in v3.4.1, but I'm hesitant to call this
a bug without intimate knowledge of the source. Any help would be greatly
appreciated.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with serialization via readRDS() on a textConnection()

Duncan Murdoch-2
(Sorry for not linking to your message; I accidentally deleted the
original copy of your message.)

Your code

 > zz = textConnection('tempConnection', 'wb')
 > saveRDS(c("a", "b", "c"), zz, ascii = TRUE)
 > serialized_obj = paste(textConnectionValue(zz), collapse='\n')
 > readRDS(textConnection(serialized_obj))
Error in gzcon(file) : 'read' not enabled for this connection

has one problem:  textConnectionValue(zz) may not be the complete text
because zz hasn't been closed.  You should close(zz), then get the
result from the variable tempConnection.

However, this doesn't fix the problem you saw, which appears to be a bug
in readRDS or gzcon.  I'll post it to the bug list.

Duncan Murdoch

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with serialization via readRDS() on a textConnection()

Duncan Murdoch-2
On 09/08/2017 9:01 AM, Duncan Murdoch wrote:

> (Sorry for not linking to your message; I accidentally deleted the
> original copy of your message.)
>
> Your code
>
>  > zz = textConnection('tempConnection', 'wb')
>  > saveRDS(c("a", "b", "c"), zz, ascii = TRUE)
>  > serialized_obj = paste(textConnectionValue(zz), collapse='\n')
>  > readRDS(textConnection(serialized_obj))
> Error in gzcon(file) : 'read' not enabled for this connection
>
> has one problem:  textConnectionValue(zz) may not be the complete text
> because zz hasn't been closed.  You should close(zz), then get the
> result from the variable tempConnection.
>
> However, this doesn't fix the problem you saw, which appears to be a bug
> in readRDS or gzcon.  I'll post it to the bug list.

Now posted as https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17325.

Duncan Murdoch

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Loading...