tar
Create, Extract or List tar Archives

### Description

Creates, extracts, or lists a tar archive.

### Usage

    tar(tarfile, files = NULL, compression = c("none", "gzip", "bzip2", "xz"),
        compression_level = 6, tar = Sys.getenv("TAR", unset="tar"), extra_flags = "")
    untar(tarfile, files = NULL, list = FALSE, exdir = ".", compressed = NA,
        extras = NULL, verbose = FALSE, tar = Sys.getenv("TAR", unset="tar"))

### Arguments

tarfile | a character string or a connection specifying the tar archive file.
files | a character vector specifying the paths of files or directories to be added to or extracted from the tar archive. For tar, the default adds all files under the current work directory to the tar archive. For untar, the default lists or extracts all files contained in the tar archive file.
compression | a character string giving the compression method. The default is "none"; the only supported compression is "gzip". The values "bzip2" and "xz" are accepted but treated as "gzip".
compression_level | an integer with a value between 0 and 9, inclusive. Indicates the amount of compression to use when writing to a connection. Used only when compression is "gzip", "bzip2", or "xz". See connections.
tar | a character string specifying the path of tar command. The default value is defined in the system environment "TAR". tar and untar always use an external executable, and the special value "internal" is ignored.
extra_flags, extras | a character string specifying the extra flags for an external tar command.

list | a logical flag. If TRUE, lists the file paths from the tar archive. If FALSE, extracts the files from tar archive.
exdir | a character string specifying the directory to extract files. The default is the current working directory. It is created if the specified directory does not exist.
compressed | a character string giving the compressed method that the tar achieve is used. It could be "gzip", "bzip2", or "xz" (partial matching is accepted). It can be the logical value TRUE, in which case "gzip" is used. The default NA specifies that the compression method is taken from the header field of archive file.
verbose | a logical value. If TRUE, the echo message is displayed for an external untar command.

### Details

tar and untar are wrapper functions for external tar commands. There could be more command flags, depending on the external tar command. Some commands or flags could be different from the platform's (Unix or Windows) commands or flags.
Value

tar | returns the code from running system for an external tar command. (Zero indicates success.)
untar | If list = TRUE, returns a character containing the paths of files for an internal untar. Otherwise, returns the code from running system for an external untar command. (Zero indicates success.)

References
TAR format. http://en.wikipedia.org/wiki/Tar_(computing).
See Also
system, zip, connections, readBin
Examples

    ## Not run:
    # use external tar.exe to compress all the files under c:/temp
    tar("tarfile", files = "c:/temp",  tar = "tar.exe")
    # use internal tar implementation of "xz" method to compress all the files under current directory.
    tar("tarfile", compression = "xz")
    # use the internal tar to list the file names in "tarfile"
    untar("tarfile", list = TRUE)
    # use the external tar.exe to extract the files from "tarfile" to directory "./temp" with echo message.
    untar("tarfile", tar = "tar.exe", exdir = "./temp", verbose = TRUE)

    ## End(Not run)

Package utils version 6.1.5-18
Package Index