[R] Compression variable in memory with gzcon

Wush Wu wush978 at gmail.com
Sun Nov 9 13:27:49 CET 2014


Hello,

I cannot figure out how to compress a raw vector in memory with gzip format
that is compatible with `gzfile`. (`memCompress` does not compatible with
`gzfile`.)

I modified the example in `rawConnection`, but it does not work:

```
> zz <- gzcon(rawConnection(raw(0), "r+b")) # start with empty raw vector
Error in gzcon(rawConnection(raw(0), "r+b")) :
  can only use read- or write- binary connections
```

If I used a write-only connections, then writing is ok but I don't know how
to read the data after writing. The `rawConnectionValue` won't work:

```
> zz <- gzcon(con1 <- rawConnection(raw(0), "wb")) # start with empty raw
vector
> writeBin(LETTERS, zz)
> flush(zz)
> rawConnectionValue(con1)
R(18294,0x7fff73eff310) malloc: *** mach_vm_map(size=140652713885696)
failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

R(18294,0x7fff73eff310) malloc: *** mach_vm_map(size=140652713885696)
failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Error: cannot allocate vector of size 130993.0 Gb
```

Note that the above script works if I remove the `gzcon`. Is there another
way to read the raw vector from the connection?

Here is my `sessionInfo`:

```
> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] zh_TW.UTF-8/zh_TW.UTF-8/zh_TW.UTF-8/C/zh_TW.UTF-8/zh_TW.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
```

Thanks,
Wush
PhD Student Graduate Institute of Electrical Engineering, National Taiwan
University

	[[alternative HTML version deleted]]



More information about the R-help mailing list