'unzipping gz file in R

Some R code that used to work to download and unzip .gz files from PubMed is no longer working. Here's a reproducible example:

filez = "pubmed22n1148.xml.gz"
url = paste('ftp://ftp.ncbi.nlm.nih.gov/pubmed/updatefiles/', filez, sep='')
zipped.file = download.file(url = url, destfile=filez) 
gunzip(filez) 

The error is:

Error in readBin(inn, what = raw(0L), size = 1L, n = BFR.SIZE) : 
  error reading from the connection
In addition: Warning message:
In readBin(inn, what = raw(0L), size = 1L, n = BFR.SIZE) :
  invalid or incomplete compressed data

I'm using R version 4.1.1 and gunzip is from the R.utils package version 2.11.0. The files do not appear to be downloading correctly, as I can use gunzip on a manually downloaded .gz file. I've experimented with different methods for download.file.

r


Sources

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

Source: Stack Overflow

Solution Source