'Compress files from a directory in gzip format (*.gz)

I have a directory that contains files with different file extensions and I have to compress them one by one because the 7z program does not allow me to do it massively. for Example:

  • List item

  • file1.xyz

  • file2.rrr

  • file3.qwe

  • file250.pep

expected output

  • file1.xyz.gz

  • file2.rrr.gz

  • file3.qwe.gz

  • file250.pep.gz

any idea how to do this in R? thank you

r


Solution 1:[1]

Yes you can do this in R. Assuming your files are in a subdirectory called files:

files  <- dir("./files/", full.names = TRUE)
lapply(files, R.utils::gzip, remove = FALSE)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SamR