Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract bz2 file in R

Tags:

r

bzip2

I have bunch of .csv.bz2 files, which i have to download, extract, and read in R. I downloaded the file and want to extract it to current working directory, then read it. unz(filename,filename.csv) but it does not seem to work. How can I do that?

I heard somewhere that bzfiles can be read directly without decompressing. How can I do that?

like image 412
Prabhu Avatar asked Sep 20 '14 12:09

Prabhu


People also ask

How do I unzip a BZ2 file?

bz2 file simply right-click the file you want to extract and select “Extract”. Windows users will need a tool named 7zip to extract tar. bz2 files. For more verbose output use the -v option.


1 Answers

You can use any of these two commands:

  1. read.csv()command: with this command you can directly supply your compressed filename containing csv file.

    read.csv("file.csv.bz2")

  2. read.table() command: This command is generic version of read.csv() command. You can set delimiters and others options that read.csv() automatically sets. You don't need to uncompress the file separately. This command does it automatically for you.

    read.csv("file.csv.bz2", header = TRUE, sep = ",", quote = "\"",...)

like image 78
Amrit Shrestha Avatar answered Sep 19 '22 15:09

Amrit Shrestha