Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use R language to extract and compress .tar.gz.zip and other format files

Shulou Source: shulou.com Published: 2022-06-02 17:33:48 10月29日 Update

This article mainly explains "how to use R language to extract and compress .tar.gz.zip and other format files". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use R language to extract and compress .tar.gz.zip and other format files" bar!

.zip

Compression: zip ()

Decompress: unzip ()

To compress the file, enter the compressed file name directly in the first parameter of the zip () function, and enter the file name before compression in the second parameter.

It is even easier to extract the file, just use unzip () to add the name of the file that needs to be extracted.

.tar.gz

Compression: tar ()

Decompress: untar ()

A compressed file with the same .zip suffix.

.gz and .bz2

These two compressed files are the most different from the previous ones, because the files with these two suffixes can be called compressed files, or they can be read directly as a data file as data frame. Because it is a data file.

Let's explain in detail by decompressing / reading:

1) decompress directly

There is no function to extract the related files by default in R, so you need to use a package: R.utils, and then, as shown in the following code, you can extract it using the gunzip () function.

Library (R.utils) gunzip ("file.gz", remove = `TRUE`) bunzip2 ("file.bz2", remove = `TRUE`)

Note that there is an extra remove = parameter in this function. If you select TRUE, only the extracted files will be retained, and the original package will be deleted. The default is TRUE.

After decompression, we can read it directly with read.table ().

2) read directly

Of course, if our goal is to read the data, and not necessarily to extract it, we can read the data directly in the form of a combination of two default functions:

Dat

Tags: File function format language that is data parameters learning two content suffix file name input distinctive code just name form idea situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple Shulou Information macOS Docker