Package: archive 1.1.11
archive: Multi-Format Archive and Compression Support
Bindings to 'libarchive' <http://www.libarchive.org> the Multi-format archive and compression library. Offers R connections and direct extraction for many archive formats including 'tar', 'ZIP', '7-zip', 'RAR', 'CAB' and compression formats including 'gzip', 'bzip2', 'compress', 'lzma' and 'xz'.
Authors:
archive_1.1.11.tar.gz
archive_1.1.11.tar.gz(r-4.5-noble)archive_1.1.11.tar.gz(r-4.4-noble)
archive_1.1.11.tgz(r-4.4-emscripten)archive_1.1.11.tgz(r-4.3-emscripten)
archive.pdf |archive.html✨
archive/json (API)
NEWS
# Install 'archive' in R: |
install.packages('archive', repos = 'https://cloud.r-project.org') |
Bug tracker:https://github.com/r-lib/archive/issues
Pkgdown site:https://archive.r-lib.org
Conda-Forge:r-archive-1.1.11(2025-02-05)
Last updated 30 days agofrom:5fa376ab4d. Checks:3 OK. Indexed: no.
Target | Result | Latest binary |
---|---|---|
Doc / Vignettes | OK | Mar 07 2025 |
R-4.5-linux-x86_64 | OK | Mar 07 2025 |
R-4.4-linux-x86_64 | OK | Mar 07 2025 |
Exports:archivearchive_extractarchive_readarchive_writearchive_write_dirarchive_write_filesfile_readfile_write
Dependencies:clifansigluelifecyclemagrittrpillarpkgconfigrlangtibbleutf8vctrs
Citation
To cite package ‘archive’ in publications use:
Hester J, Csárdi G (2025). archive: Multi-Format Archive and Compression Support. R package version 1.1.11, https://CRAN.R-project.org/package=archive.
Corresponding BibTeX entry:
@Manual{, title = {archive: Multi-Format Archive and Compression Support}, author = {Jim Hester and Gábor Csárdi}, year = {2025}, note = {R package version 1.1.11}, url = {https://CRAN.R-project.org/package=archive}, }
Readme and manuals
archive
R bindings to libarchive http://www.libarchive.org. Supports many archives formats, including tar, ZIP, 7-zip, RAR, CAB. Also supports many filters such as gzip, bzip2, compress, lzma, xz and uuencoded files, among others.
archive provides interfaces to read and write connections into archives, as well as efficiently reading and writing archives directly to disk.
Installation
You can install archive from CRAN with:
# install.packages("archive")
Example
Single file archives
Use archive_read()
and archive_write()
to read and write single
files to an archive. These files return connections, which can be passed
to any R interface which can take a connection. Most base R file system
functions use connections, as well as some packages like
readr.
library(readr) # read_csv(), write_csv(), cols()
# Write a single dataset to zip
write_csv(mtcars, archive_write("mtcars.zip", "mtcars.csv"))
# Read the data back, by default the first file is read from the archive.
read_csv(archive_read("mtcars.zip"), col_types = cols())
#> # A tibble: 32 × 11
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
#> # ℹ 28 more rows
# Also supports things like archiving and compression together
# Write a single dataset to (gzip compressed) tar
write_csv(mtcars, archive_write("mtcars.tar.gz", "mtcars.csv", options = "compression-level=9"))
# Read the data back
read_csv(archive_read("mtcars.tar.gz"), col_types = cols())
#> # A tibble: 32 × 11
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
#> # ℹ 28 more rows
# Archive file sizes
file.size(c("mtcars.zip", "mtcars.tar.gz"))
#> [1] 742 808
Multi file archives
archive_write_files()
is used to create a new archive from multiple
files on disk.
# Write a few files to the temp directory
write_csv(iris, "iris.csv")
write_csv(mtcars, "mtcars.csv")
write_csv(airquality, "airquality.csv")
# Add them to a new archive
archive_write_files("data.tar.xz", c("iris.csv", "mtcars.csv", "airquality.csv"))
# View archive contents
a <- archive("data.tar.xz")
a
#> # A tibble: 3 × 3
#> path size date
#> <chr> <int> <dttm>
#> 1 iris.csv 3716 2023-12-11 12:18:04
#> 2 mtcars.csv 1281 2023-12-11 12:18:04
#> 3 airquality.csv 2890 2023-12-11 12:18:04
# By default `archive_read()` will read the first file from a multi-file archive.
read_csv(archive_read("data.tar.xz"), col_types = cols())
#> # A tibble: 150 × 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> # ℹ 146 more rows
# Use a number to read a different file
read_csv(archive_read("data.tar.xz", file = 2), col_types = cols())
#> # A tibble: 32 × 11
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
#> # ℹ 28 more rows
# Or a filename to read a specific file
read_csv(archive_read("data.tar.xz", file = "mtcars.csv"), col_types = cols())
#> # A tibble: 32 × 11
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
#> # ℹ 28 more rows
Regular files (with compression)
file_write()
returns a connection to filtered by one or more
compressions or encodings. file_read()
reads a compressed file,
automatically detecting the compression used.
# Write bzip2, uuencoded data
write_csv(mtcars, file_write("mtcars.bz2", filter = c("uuencode", "bzip2")))
# Read it back, the formats are automatically detected
read_csv(file_read("mtcars.bz2"), col_types = cols())
#> # A tibble: 32 × 11
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
#> # ℹ 28 more rows
Help Manual
Help page | Topics |
---|---|
Construct a new archive | archive |
Extract contents of an archive to a directory | archive_extract |
Create a readable connection to a file in an archive. | archive_read |
Create a writable connection to a file in an archive. | archive_write |
Add files to a new archive | archive_write_dir archive_write_files |
Construct a connections for (possibly compressed) files. | file_connections file_read file_write |