file_connections: Construct a connections for (possibly compressed) files.

file_readR Documentation

Construct a connections for (possibly compressed) files.

Description

They are functionally equivalent to calling archive_read or archive_write using ⁠format = "raw", archive = file⁠.

Usage

file_read(file, mode = "r", filter = NULL, options = character())

file_write(file, mode = "w", filter = NULL, options = character())

Arguments

file

character(1) || integer(1) The filename within the archive, specified either by filename or by position.

mode

character(1) A description of how to open the connection (if it should be opened initially). See section ‘Modes’ in base::connections() for possible values.

filter

character(1) default: NULL The archive filter, one of \evalchoices_rd(names(archive:::archive_filters())). Supported filters differ depending on the libarchive version and build.

options

character() default: character(0) Options to pass to the filter or format. The list of available options are documented in options can have one of the following forms:

  • option=value The option/value pair will be provided to every module. Modules that do not accept an option with this name will ignore it.

  • option The option will be provided to every module with a value of "1".

  • !option The option will be provided to every module with a NULL value.

  • module:option=value, module:option, module:!option As above, but the corresponding option and value will be provided only to modules whose name matches module. See read options for available read options See write options for available write options

Details

file_write() returns an writable output connection, file_read() returns a readable input connection.

Value

An 'archive_read' connection (for file_read()) or an 'archive_write' connection (for file_write()) to the file.

Examples

if (archive:::libarchive_version() > "3.2.0") {
# Write bzip2, base 64 encoded data and use high compression
write.csv(mtcars,
  file_write("mtcars.bz2",
    filter = c("uuencode", "bzip2"),
    options = "compression-level=9"
  )
)

# Read it back
read.csv(file_read("mtcars.bz2"), row.names = 1, nrows = 3)
unlink("mtcars.bz2")
}

archive documentation built on Sept. 13, 2024, 1:07 a.m.