From pd@lgd @ending from gm@il@com  Thu Nov  8 11:41:51 2018
From: pd@lgd @ending from gm@il@com (peter dalgaard)
Date: Thu, 8 Nov 2018 11:41:51 +0100
Subject: [Rd] error unserializing ascii format (v2 or v3)
In-Reply-To: <CAHPe-e-QwCV7Q3O4nqtFt0VfSDQbsx8BoSekG8FsigE7-vnqbw@mail.gmail.com>
References: <CAHPe-e-QwCV7Q3O4nqtFt0VfSDQbsx8BoSekG8FsigE7-vnqbw@mail.gmail.com>
Message-ID: <D15639B9-06F7-4EE2-A075-5C44FC86FBAA@gmail.com>

I see this on MacOS as well, so likely not platform dependent. 

A little more diddling to try to narrow it down:

> unserialize(serialize(as.raw(1), NULL, version=2, ascii=TRUE))
[1] 30
> unserialize(serialize(list(as.raw(1)), NULL, version=2, ascii=TRUE))
[[1]]
[1] 30

> unserialize(serialize(list(raw=as.raw(1)), NULL, version=2, ascii=TRUE))
Error in unserialize(serialize(list(raw = as.raw(1)), NULL, version = 2,  : 
  'installTrChar' must be called on a CHARSXP, but got 'pairlist'
> unserialize(serialize(list(r=as.raw(1)), NULL, version=2, ascii=TRUE))
Error in unserialize(serialize(list(r = as.raw(1)), NULL, version = 2,  : 
  'installTrChar' must be called on a CHARSXP, but got 'pairlist'
> unserialize(serialize(list(r=1), NULL, version=2, ascii=TRUE))
$r
[1] 1

> unserialize(serialize(list(as.raw(c(1,2))), NULL, version=2, ascii=TRUE))
[[1]]
[1] 30 31


So it looks like there is an issue with reading a named list containing a raw vector. Unnamed lists work and so does non-raw vectors. The length of the vector doesn't seem to matter and neither does the actual name. 

You can vary the error message by varying the entries in the vector, but the gist of it is that something gets misinterpreted and the rest of the data stop making sense.

I also tried going explicitly through a text connection, and that seems exactly equivalent. 

-pd

> On 7 Nov 2018, at 23:35 , Michael Sannella via R-devel <r-devel at r-project.org> wrote:
> 
> I ran into an interesting error unserializing a file created with
> ascii=TRUE:
> 
> R 3.5.1 (Windows or Linux):
>> unserialize(serialize(list(raw=as.raw(c(39,41))), NULL, version=2,
> ascii=TRUE))
>    Error in unserialize(serialize(list(raw = as.raw(c(39, 41))), NULL,
> version = 2,  :
>      ReadItem: unknown type 29, perhaps written by later version of R
> 
> The same error happens when the serialization is done with version=2
> or version=3.  It does not happen if the serialization is done with
> ascii=FALSE.
> 
> Note that 0x29 == 41.  It looks like unserialize is reading the wrong
> line.
> 
> I tried this in earlier versions of R on Windows, and the same error
> happens in every version from R-2.15.3 (the earliest I have) on up.
> 
>  ~~ Michael Sannella
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] error unserializing ascii format (v2 or v3)
peter dalgaard