Description Usage Arguments Details Value See Also Examples
gzcon
provides a modified connection that wraps an existing
connection, and decompresses reads or compresses writes through that
connection. Standard gzip
headers are assumed.
1 |
con |
a connection. |
level |
integer between 0 and 9, the compression level when writing. |
allowNonCompressed |
logical. When reading, should non-compressed input be allowed? |
If con
is open then the modified connection is opened. Closing
the wrapper connection will also close the underlying connection.
Reading from a connection which does not supply a gzip
magic
header is equivalent to reading from the original connection if
allowNonCompressed
is true, otherwise an error.
Compressed output will contain embedded NUL bytes, and so con
is not permitted to be a textConnection
opened with
open = "w"
. Use a writable rawConnection
to
compress data into a variable.
The original connection becomes unusable: any object pointing to it will now refer to the modified connection. For this reason, the new connection needs to be closed explicitly.
An object inheriting from class "connection"
. This is the same
connection number as supplied, but with a modified internal
structure. It has binary mode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ## Uncompress a data file from a URL
z <- gzcon(url("http://www.stats.ox.ac.uk/pub/datasets/csb/ch12.dat.gz"))
# read.table can only read from a text-mode connection.
raw <- textConnection(readLines(z))
close(z)
dat <- read.table(raw)
close(raw)
dat[1:4, ]
## gzfile and gzcon can inter-work.
## Of course here one would use gzfile, but file() can be replaced by
## any other connection generator.
zz <- gzfile("ex.gz", "w")
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")
close(zz)
readLines(zz <- gzcon(file("ex.gz", "rb")))
close(zz)
unlink("ex.gz")
zz <- gzcon(file("ex2.gz", "wb"))
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")
close(zz)
readLines(zz <- gzfile("ex2.gz"))
close(zz)
unlink("ex2.gz")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.