Skip to content
Prev 385488 / 398506 Next

serialize does not work as expected

On 29/08/2020 11:34 a.m., Sigbert Klinke wrote:
Objects like 1:3 are stored in a special compact form, where 1:3 takes 
up the same space as 1:1000000.  Apparently as.numeric() knows to work 
with that special form, and produces the numeric version of it.

You can confirm this by looking at the results of

serialize(l[[i]], connection=stdout(), ascii=TRUE)

for each of i=1,2,3:

 > for (i in 1:3) {
+  cat("\nElement", i, "\n")
+  serialize(l[[i]], connection=stdout(), ascii=TRUE)
+ }

Element 1
A
3
262146
197888
5
UTF-8
238
2
1
262153
14
compact_intseq
2
1
262153
4
base
2
13
1
13
254
14
3
3
1
1
254

Element 2
A
3
262146
197888
5
UTF-8
238
2
1
262153
15
compact_realseq
2
1
262153
4
base
2
13
1
14
254
14
3
3
1
1
254

Element 3
A
3
262146
197888
5
UTF-8
14
3
1
2
3

Notice how element 1 is a "compact_intseq" and element 2 is a 
"compact_realseq".

Duncan Murdoch