Error code 1 when trying to unzip bin.gz file - r

I was following along this SO post on how to download and unzip a file.
url <- 'https://s3.amazonaws.com/dl4j-distribution/GoogleNews-vectors-negative300.bin.gz'
file <- basename(url)
download.file(url, file)
tmpdir <- tempdir()
untar(file, compressed = 'gzip', exdir = tmpdir)
Everything runs fine in the above block except the last line which returns
> untar(file, compressed = 'gzip', exdir = tmpdir)
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
Warning message:
In untar(file, compressed = "gzip", exdir = tmpdir) :
‘/usr/bin/tar -xf 'GoogleNews-vectors-negative300.bin.gz' -C '/var/folders/ll/g08vjcnd33vdhf250bbg9230fdw13f/T//RtmpAICV5a'’ returned error code 1
How can I unzip GoogleNews-vectors-negative300.bin.gz after downloading it?

Related

Reading a vcf.bgz file in R

I downloaded some data from gnomad - https://gnomad.broadinstitute.org/downloads. it comes in the form of VCF.bgz file and I would like to read it as a vcf file.
i wrote some code:
install.packages("R.utils")
library("R.utils")
df=gunzip("gnomad.exomes.r2.1.1.sites.4.vcf.bgz", "gnomad.exomes.r2.1.1.sites.4.vcf")
install.packages("vcfR")
library("vcfR")
vc=read.vcfR("gnomad.exomes.r2.1.1.sites.4.vcf.bgz")
but it doesn't work -- it doesn't convert it to appropriate VCF file.
Warning message:
In file.remove(filename) :
cannot remove file 'gnomad.exomes.r2.1.1.sites.4.vcf.bgz', reason 'Permission denied'
Error in read.vcfR(df) :
File: gnomad.exomes.r2.1.1.sites.4.vcf does not appear to be a VCF file.
First line of file:
gnomad.exomes.r2.1.1.sites.4.vcf
Should begin with:
##fileformat=VCFv
In addition: Warning message:
In scan(file = file, what = character(), nmax = 1, sep = "\n", quiet = TRUE, :
embedded nul(s) found in input
would appreciate any help, thank you:)

How to download a .zip file located on Google Drive?

I am trying to download a .shp file that is inside a .zip file. This .zip file is on https://drive.google.com/drive/u/2/folders/1u5oO0h9YKL1Nfi_pLGJgcEGGvUBJnE7D. I tried:
url = "https://drive.google.com/drive/u/2/folders/1u5oO0h9YKL1Nfi_pLGJgcEGGvUBJnE7D"
dir = tempdir()
temp = tempfile(fileext = ".zip", tmpdir = dir)
googledrive::drive_download(url, path = temp, overwrite = T)
And I got this error:
Error in `cli::cli_abort()`:
! Cannot export Google file of type:
* application/vnd.google-apps.folder
as a file of type:
* application/zip
How do I download it?

R Markdown Error: Error in tempfile(pattern = "_rs_rdf_", tmpdir = outputFolder, fileext = ".rdf") : temporary name too long

I am working on RMarkdown and keep getting the following error when I run my code. W
Error in tempfile(pattern = "_rs_rdf_", tmpdir = outputFolder, fileext = ".rdf") :
temporary name too long
However, hen I paste the code in the console, it works. I can even knit the document successfully. What is the problem and how can one resolve this?

R: unable to download file

I wan to download a file using the following request:
request <- 'http://earthserver.ecmwf.int/rasdaman/ows?service=WCS&version=2.0.1&request=ProcessCoverages&query=for c in (geff_fire_weather_index) return encode(c[Lat(35:47),Long(6:18),ansi("2015-01-01T00:00":"2015-12-31T00:00")],"netcdf")'
download.file(url = request, destfile = "rea.nc")
If I run this using the browser it works no problem but in R it fails with the following error message:
downloaded 0 bytes
Error in download.file(url = request2, destfile = "rea.nc") :
cannot download all files
In addition: Warning message:
In download.file(url = request2, destfile = "rea.nc") :
URL 'http://earthserver.ecmwf.int/rasdaman/ows?service=WCS&version=2.0.1&request=ProcessCoverages&query=for c in (geff_fire_weather_index) return encode(c[Lat(35:47),Long(6:18),ansi("2015-01-01T00:00":"2015-12-31T00:00")],"netcdf")': status was 'Couldn't connect to server'
Is there a way to fix this?

R & figshare: corrupt zip when downloaded in R

I'm trying to make my research reproducible storing the data at figshare.
Something strange happens when I download and unzip the data in R.
here is the zip
If I download it manually, it opens ok; but when I try to get it with an R script, the downloaded archive is corrupt. Any ideas where is the problem?
the code to reproduce my error
url <- 'https://ndownloader.figshare.com/files/4797355'
path <- 'test/missing_data_raw.zip'
ifelse(file.exists(path1), yes = 'file alredy exists', no = download.file(url1, path1))
unzip(zipfile = path1,exdir = 'test')
Try setting the download mode to binary explicitly:
url <- 'https://ndownloader.figshare.com/files/4797217'
path1 <- tempfile(fileext = ".zip")
if (file.exists(path1)) 'file alredy exists' else download.file(url, path1, mode="wb")
unzip(zipfile = path1,exdir = tempdir())

Resources