Kompresi atau dekompresi dalam memori untuk vektor mentah.
memCompress(from, type = c("gzip", "bzip2", "xz", "none"))<p></p><p>memDecompress(from,
type = c("unknown", "gzip", "bzip2", "xz", "none"),
asChar = FALSE)</p>
| Parameter | Deskripsi |
|---|---|
from |
A raw vector. For memCompress a character vector will be converted to a raw vector with character strings separated by "\n". |
type |
character string, the type of compression. May be abbreviated to a single letter, defaults to the first of the alternatives. |
asChar |
logical: should the result be converted to a character string? |
# NOT RUN {
txt <- readLines(file.path(R.home("doc"), "COPYING"))
sum(nchar(txt))
txt.gz <- memCompress(txt, "g")
length(txt.gz)
txt2 <- strsplit(memDecompress(txt.gz, "g", asChar = TRUE), "\n")[[1]]
stopifnot(identical(txt, txt2))
txt.bz2 <- memCompress(txt, "b")
length(txt.bz2)
## can auto-detect bzip2:
txt3 <- strsplit(memDecompress(txt.bz2, asChar = TRUE), "\n")[[1]]
stopifnot(identical(txt, txt3))
## xz compression is only worthwhile for large objects
txt.xz <- memCompress(txt, "x")
length(txt.xz)
txt3 <- strsplit(memDecompress(txt.xz, asChar = TRUE), "\n")[[1]]
stopifnot(identical(txt, txt3))
# }