View source: R/archive_write.R
archive_write | R Documentation |
Create a writable connection to a file in an archive.
archive_write(
archive,
file,
mode = "w",
format = NULL,
filter = NULL,
options = character()
)
archive |
|
file |
|
mode |
|
format |
|
filter |
|
options |
|
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.
An 'archive_write' connection to the file within the archive to be written.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.