archive_write {archive} | R Documentation |
Create a writable connection to a file in an archive.
Description
Create a writable connection to a file in an archive.
Usage
archive_write(
archive,
file,
mode = "w",
format = NULL,
filter = NULL,
options = character()
)
Arguments
archive |
|
file |
|
mode |
|
format |
|
filter |
|
options |
|
Details
If format
and filter
are NULL
, they will be set automatically based on
the file extension given in file
when writing and automatically detected
using
Robust automatic format detection
when reading.
For traditional zip archives archive_write()
creates a connection which
writes the data to the specified file directly. For other archive formats
the file size must be known when the archive is created, so the data is
first written to a scratch file on disk and then added to the archive. This
scratch file is automatically removed when writing is complete.
Value
An 'archive_write' connection to the file within the archive to be written.
Examples
# Archive format and filters can be set automatically from the file extensions.
f1 <- tempfile(fileext = ".tar.gz")
write.csv(mtcars, archive_write(f1, "mtcars.csv"))
archive(f1)
unlink(f1)
# They can also be specified explicitly
f2 <- tempfile()
write.csv(mtcars, archive_write(f2, "mtcars.csv", format = "tar", filter = "bzip2"))
archive(f2)
unlink(f2)
# You can also pass additional options to control things like compression level
f3 <- tempfile(fileext = ".tar.gz")
write.csv(mtcars, archive_write(f3, "mtcars.csv", options = "compression-level=2"))
archive(f3)
unlink(f3)