Search code examples
rcsvknitrr-markdownbzip2

Error knitting Rmarkdown doc: Error in bzfile(filename, "rb") : cannot open the connection


So I am trying to knit my code for an assignment on Coursera but I am encountering a strange error and I cant figure out the issue. Here is the code that I believe is the problem

setInternet2(use = TRUE)


fileUrl<- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"

download.file(fileUrl, destfile = "c:/Users/musto101/Dropbox/DataScience/ReproducibleResearch/Assignment2/data/stormData.csv.bz2")



dateDownloaded<- date()

library(R.utils)



stormData<-bunzip2( filename = "stormData.csv", destname = "stormData3.csv")



head(stormData)

and the error:

Quitting from lines 13-35 (PA2.Rmd) 
Error in bzfile(filename, "rb") : cannot open the connection
Calls: <Anonymous> ... eval -> eval -> bunzip2 -> bunzip2.default -> bzfile
In addition: Warning messages:
1: package 'R.utils' was built under R version 3.1.1 
2: package 'R.oo' was built under R version 3.1.1 
3: package 'R.methodsS3' was built under R version 3.1.1 
4: In bzfile(filename, "rb") :
  cannot open bzip2-ed file 'stormData.csv', probable reason 'No such file or directory'
Execution halted

So does anyone have a clue what is going on here? Any advice would be gratefully received.

Thanks


Solution

  • Looks like you forgot the .BZ2 suffix on the input filename. Code below should fix this.

    stormData<-bunzip2( filename = "stormData.csv.bz2", destname = "stormData3.csv")