tar, untar

Use R to create a tarball (tar.gz zip file) or to unzip a tarball.
tar(tarfile, files = NULL)
  • tarfile – Name of the tar.gz file to be generated.
  • files – List of files to be placed into the tarball.
untar(tarfile, exdir = “.”)
  • tarfile – Name of the tar.gz file to be unzipped.
  • exdir – Where to put the files.

Example. Code from yesterday’s post was run to download .R files from RFunction.com posts in February 2012 and save them into a folder, then those files are zipped into a tarball. In the second part, I download the source of the stockPortfolio package and unzip the tar.gz file.
> #______ Download Feb 2012 Code Files, Zip Into Tarball ______#
> source("http://rfunction.com/code/1203/120323.R")
Loading required package: bitops
> tar("RFunction_Code_1202.tar.gz", "1202")
> #______ Download, Unzip Package ______#
> URL <- "http://cran.r-project.org/src/contrib/stockPortfolio_1.2.tar.gz"
> download.file(URL, "tempPack.tar.gz")
trying URL 'http://cran.r-project.org/src/contrib/stockPortfolio_1.2.tar.gz'
Content type 'application/x-gzip' length 59107 bytes (57 Kb)
opened URL
downloaded 57 Kb

> dir.create("stockPortfolio")
> untar("tempPack.tar.gz", files="stockPortfolio") 
> list.files("stockPortfolio")
[1] "data"        "DESCRIPTION" "man"         "MD5"        
[5] "NAMESPACE"   "R"          

Leave a Reply