| zipArchive {Rcompression} | R Documentation |
This is a simple function that takes the name of a file
and labels it with an S3 class so that programmers
can then access information about and contents in
the ZIP archive. The purpose of this is function
is to return an object with the appropriate information
so that the external ZIP file/archive can be treated
as a list via $, [ and [[ operations
and one can add elements via [[<-.
By default, this checks the file exists. If one wants
to use this to identify a ZIP file that you will create,
you will want to use check = FALSE.
The class parameter allows more specialized
constructors to use this function to create objects
with more detailed class information. Using
setOldClass would probably be
more appropriate.
zipArchive(filename, check = TRUE, class = "ZipArchive")
filename |
the name of the ZIP file. This is passed to path.expand. |
check |
a logical value indicating whether to raise an error if the file doesn't exist. |
class |
a character vector giving the name(s) of the S3 classes for the resulting object. |
A character vector giving the expanded name of the specified file
with the specified class vector as the class attribute.
For the element accessor operators ($, [ and [[),
the contents of the specified file(s) within the archive are returned.
For the assignment operators ($<-, [<- and [[<-),
the updated archive object is returned.
Duncan Temple Lang
f = system.file("sampleData", "MyZip.zip", package = "Rcompression")
ar = zipArchive(f)
names(ar)
length(ar)
ar[["FAQ.html"]]
ar[["bunzip"]] # partial matching
ar[".*"] # regular expression
f = system.file("sampleData", "tests.zip", package = "Rcompression")
ar = zipArchive(f)
names(ar)
length(ar)
# This needs a password to access the contents of any of the file.
# The password is the string "password" (pretty simple).
ar[["files.R", password = "password"]]
# without the password, we'd have an error.
try(ar[["files.R"]])
#
f = system.file("sampleData", "Empty.docx", package = "Rcompression")
tgt = paste(tempdir(), "word.docx", sep = .Platform$file.sep)
file.copy(f, tgt)
ar = zipArchive(tgt)
tmp = tempfile()
cat("This is some text\nin a file", file = tmp)
ar[["fromFile"]] = tmp
ar[["fromAsIs"]] = I("Text/that/shouldn't be mistaken for a file")
ar[["fromText"]] = "more heuristic text"
names(ar)
ar["one"] = tmp
ar[c("two", "fromAsIs")] = list(tmp, I("Text/that/shouldn't be mistaken for a file"))
names(ar)
####
# In memory archives
contents = loadZip(system.file("sampleData", "Empty.docx", package = "Rcompression"))
ar = zipArchive(contents)
names(ar)
length(ar)
if(require(RCurl)) {
data = getURLContent('http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip?1a1b5dbb25d31898b347736783bd440a')
ar = zipArchive(data)
read.csv(textConnection(ar[[1]]), header = TRUE, na.strings = "N/A")
}