I'm trying to read this xbrl file with R XBRL package...
https://www.cnmv.es/Portal/Consultas/wuc/DescargaXBRLIPP.ashx?t={77853e69-5deb-4bd5-acd4-3fb4715e2664}
...but when I download the file and run the code
xbrl.vars <- xbrlDoAll(inst, verbose=TRUE)
I get this error:
error in XBRL::xbrlParse(file) :
./ipp-enc-ind-2005-06-30.xsd./ipp-enc-con-2005-06-30.xsd does not exists. Aborting.
I suppose that the error is a problem with the ULR of the .xsd file. Is it possible to download the xsd files in a local directory and use them to read the .XBRL file? How can it be done?
Related
I am trying to download and unzip a folder of files from GitHub into R. I can manually download the file at https://github.com/dylangomes/SO/blob/main/Shape.zip and then extract all files in working directory, but I'd like to work directly from R.
utils::unzip("https://github.com/dylangomes/SO/blob/main/Shape.zip")
# Warning message:
# In utils::unzip("https://github.com/dylangomes/SO/blob/main/Shape.zip", :
# error 1 in extracting from zip file
It says it is a warning message, although nothing has been downloaded or unzipped into my wd.
I can download the file to my machine:
utils::download.file("https://github.com/dylangomes/SO/blob/main/Shape.zip")
But I get the same message with the unzip function:
utils::unzip("Shape.zip")
And the downloaded file cannot manually be extracted. Here, I get the error that the compressed folder is empty. The unzip line works on the manually downloaded .zip file, which tells me something is wrong with the download.file line.
So if I add raw=TRUE to the end (which can make a difference in downloading data from GitHub):
utils::download.file("https://github.com/dylangomes/SO/blob/main/Shape.zip?raw=TRUE","Shape.zip")
utils::unzip("Shape.zip")
I get a different warning with, similarly, nothing being executed:
Warning message:
In utils::unzip("Shape.zip") : internal error in 'unz' code
I have tried most of the answers at Using R to download zipped data file, extract, and import data, but they appear to be for single files that are zipped and aren't helping here. I've tried the answers at r function unzip error 1 in extracting from zip file, which mentions the same warning message I am getting, but none of the solutions work in this case.
Any idea of what I am doing wrong?
You need to use:
download.file(
"https://github.com/dylangomes/SO/blob/main/Shape.zip?raw=TRUE",
"Shape.zip",
mode = "wb"
)
Without the query string ?raw=TRUE you are downloading the webpage and not the file.
(For Windows) R will use mode = "wb" by default when it detects from the end of the URL that certain file formats, including .zip, are being downloaded. However, the URL finishing with a query string instead of a file format means the check fails so you need to set the mode explicitly.
I receive weekly emails from a database as zip files. In the zip file is a single xls file. When I use unzip() and place the xls file into a designated shared network directory, I cannot use any xls read functions to actually access and manipulate the data (I haven't tried read.xls because of the Perl dependencies, but I'm willing to if there are no other options).
I've tried every Excel reader I can find.
read_xls(unzip(zipfile = zfile, files = "Data Extract.xls", exdir = "~\\Excel Files"))
Errors include the following where I would simply expect a dataframe output:
"libxls error: Unable to open file"
"Error in open.connection(file, "rt") : cannot open the connection
In addition: Warning message:
In open.connection(file, "rt") :
cannot open zip file 'Data.zip:F'
EDIT: It turns out that despite the DB interface calling this file within the zip an .xls file, it's an HTML file and readHTMLTable() from library(XML) did the trick just fine. Thank you for the questions which lead me to looking at ths issue from a different angle.
I was trying code given by Dirk to download and read a zipped csv file from a website. The code :
temp <- tempfile()
download.file("https://datacatalog.worldbank.org/dataset/Economic_Fitness_CSV.zip" ,temp)
I can see that the file is being read into a temp file.
temp
C:\\Users\\DCC\\AppData\\Local\\Temp\\Rtmpu61Cca\\file27346fd263d0
However, I am getting an error when I run the following code
data <- read.csv(unz(temp, "Economic_Fitness_CSV.zip"))
unlink(temp)
Warning message in unzip(temp, "C:/Users/DCC/AppData/Local/Temp/Rtmpu61Cca/Economic_Fitness_CSV.csv"):
"error 1 in extracting from zip file"
Error: 'Economic_Fitness_CSV.csv' does not exist in current working directory ('D:/MADS/02 DATA422_Data Wrangling/LABs/Lab 1').
Traceback:
I don't understand this error - how is 'Economic_Fitness_CSV.csv' supposed to exist in my working directory before it has been extracted / copied from the temp file ?
Maybe, I am missing out a simple point - but have not been able to resolve this on my own.
I am trying to download a pdf file that is stored in an internal server.
The url for this file is like this below
file_location <- "file://dory.lisa.org/research/data/test.pdf"
I tried downloading this file using the download.file option
download.file(file_location, "test.pdf",method='curl')
and i am getting an error.
curl: (37) Couldn't open file /research/data/test.pdf
Warning message:
In download.file(file_location, "test.pdf", method = "curl") :
download had nonzero exit status
I tried
url <- ('http://cran.r-project.org/doc/manuals/R-intro.pdf')
download.file(url, 'introductionToR.pdf')
And i have no problem downloading this file, but somehow it shows an error when I try to use the same approach to download a file on my server.
I'm guessing that the file does not exist at that location on your local drive. When I executed the couple of lines that downloaded from CRAN I get a pdf file in my User directory/folder. I then get success with this code:
url <- ('file://~/introductionToR.pdf')
download.file(url, 'NewintroductionToR.pdf')
So basically I succesfully exported my SQL view data into a csv file. but no when I load into Rgui software, I get the following errror:
> load("C:\\Users\\dachen\\Documents\\vTargetBuyers.csv")
Error: bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘vTargetBuyers.csv’ has magic number 'Marit'
Use of save versions prior to 2 is deprecated
What should I do? Is it the R version installed wrong? or something wrong with my CSV file?
Try using read.csv instead of load. load is for reading files created by save.
Type ?read.csv to access the documentation.