recently I am doing a project related to image recognition. And I am trying to use the MNIST dataset. I have already got some help with how to open the image file of the dataset(using readBin) but was stuck in how to open the label file. I used
to.read.label = file("~/train-labels.idx1-ubyte", "rb")
to get the connection but I dont know what to do next. Thank you for the help!
ok, I have worked it out by myself. It is actually the same idea. Just write a loop to get one number by a single time.
Related
I am using R with readxl package. I try to import an Excel file with the following command:
library(readxl)
city_codes <- read_excel("./data/file.xlsx", sheet = "city_codes")
It says it is a zip file and cannot be opened:
Error in sheets_fun(path) :
Evaluation error: zip file './data/file.xlsx' cannot be opened.
Any ideas?
I had this error, but for me, it was just that I had the sheet open in Excel while trying to read it into R. I guess the package wrongly perceives it as a zip file when it's trying to read it while Excel has partial ownership of it (and this blocks the read).
The error message is readxl's funny way of saying "file not found". That exact line of code gives me the exact same error, and the file doesn't even exist for me.
Note: I'm on version 1.0.0 of readxl
For me the "Evaluation error: zip file" error message also appeared when the excel spreadsheet was still opened in MSExcel.
You can specify a path to a file, only if it is nested on the working directory.
For example: If your working directory is MyWD and there is a folder in it, named MyData and another folder within MyData named MyNestedData, and finally myExcelFile.xlsx
read_excel("MyData/MyNestedData/myExcelFile.xlsx",sheet = "Sheet2") #will work
read_excel("MyWD/MyData/MyNestedData/myExcelFile.xlsx",sheet = "Sheet2") #will not work
If your excel worksheet is password protected, read_excel won't be able to access it and will give you this error.
If it needs protection, I would suggest p/w protecting the folder it's in, and then unprotecting the worksheet.
You may also get this error if you are using the wrong read function.
For example, read_xlsx("file.xls" ...) will throw the error.
This can happen if you forget to do the following before you use the read_excel function
setwd("C:\\map\\map_in_map\\map_in_map_in_map_where_the_file_is")
Try to change file restrictions if you are working on company's computer. This worked for me to solve this issue.
You may try to specify the full path instead of ./path/to/file
Try to make a new file. click "save as" and make a new name. Run again your code. it worked well to me :)
Although the solution was already given, but for the sake of documentation I will leave my situation here:
I ran into the same problem and couldn't figure out why. It seems that my excel file had closed with an error or something similar. I had to open the excel file, and save it again. When I ran R, everything worked smoothly.
The issue was that there was hidden files inside my working directory. I copied them to outside and exclude all directories. Now it works when I run the code.
In my case the xlsx was created using Excel 2007, which caused this issue. Xlsx files from newer Excel versions work.
In my case the file was not visible in the directory although I had deleted it. I had to search for the file using a software called "Everyting" and I deleted it. After that it worked.
For me, I was downloading a file from Google Drive into a tempfile with extension .xlsx... Realised the file in Google Drive was .xls so I changed it to that and it worked. Kinda rare situation though.
I got the same error message.
In my case the line that worked properly specified the sheet by a string (copied from excel). Suddenly, it did not work anymore (with the mentioned error message). I tried several things explained here. Ended up specifying the sheet by its number in the excel file - worked!
read_xlsx("table.xlsx", sheet="name_of_sheet") # suddently corrupt
read_xlsx("table.xlsx", sheet=4) # works
Why? No update of the package or something. I dislike to have to use a less specific line.
UPDATE: Restarting the R session made the initial line work again (although, I HAD checked the wd before...)
I have a problem that would be difficult to replicate, thats why i just want ideas of what could be behind this error. When i create a docx an want to save it in the NAS in my office, i would get this error (where doc2 is the docx and Direc4 is my direction):
Error in print.rdocx(doc2, target = Direc4) :
H:\DpProMon\DPM\Programa Monetario Diario\2021\Actas\23 Ago Informe
comité monetario y cambiario.docx is already edited. You must close
the document in order to be able to write the file.
Nevertheless, the File dont exist yet. what could be going on?
Sometimes when im triying to save an actual Word using office, i could get an error that someone else is editing the file (while thats not actually true), and that error would dissapear after a couple seconds. But in R this error doesnt stops. Some help?
In my case I couldn't find the temp file. I deleted cache, temp files from word and local, hidden files in my folder..etc. Could be because in my case I'm using GitHub desktop and also Dropbox so maybe that adds more temp files. The only solution was to change the name of the printed file each time you want to save it. Silly but works.
Can someone give me any hint why I'm getting an error message here? If I run this code where it's not in gray, it runs. When I copy/paste it to the gray section, I get an error.
Again, brand new to R here, so I'm sure it's something obvious but trying to get through an assignment and stuck here.enter image description here
My guess from the picture (post your code next time not a picture) is that your working directory isn't where your file is located. Use setwd("your file path here") to specify to R where your file of interest is located.
I am using R with readxl package. I try to import an Excel file with the following command:
library(readxl)
city_codes <- read_excel("./data/file.xlsx", sheet = "city_codes")
It says it is a zip file and cannot be opened:
Error in sheets_fun(path) :
Evaluation error: zip file './data/file.xlsx' cannot be opened.
Any ideas?
I had this error, but for me, it was just that I had the sheet open in Excel while trying to read it into R. I guess the package wrongly perceives it as a zip file when it's trying to read it while Excel has partial ownership of it (and this blocks the read).
The error message is readxl's funny way of saying "file not found". That exact line of code gives me the exact same error, and the file doesn't even exist for me.
Note: I'm on version 1.0.0 of readxl
For me the "Evaluation error: zip file" error message also appeared when the excel spreadsheet was still opened in MSExcel.
You can specify a path to a file, only if it is nested on the working directory.
For example: If your working directory is MyWD and there is a folder in it, named MyData and another folder within MyData named MyNestedData, and finally myExcelFile.xlsx
read_excel("MyData/MyNestedData/myExcelFile.xlsx",sheet = "Sheet2") #will work
read_excel("MyWD/MyData/MyNestedData/myExcelFile.xlsx",sheet = "Sheet2") #will not work
If your excel worksheet is password protected, read_excel won't be able to access it and will give you this error.
If it needs protection, I would suggest p/w protecting the folder it's in, and then unprotecting the worksheet.
You may also get this error if you are using the wrong read function.
For example, read_xlsx("file.xls" ...) will throw the error.
This can happen if you forget to do the following before you use the read_excel function
setwd("C:\\map\\map_in_map\\map_in_map_in_map_where_the_file_is")
Try to change file restrictions if you are working on company's computer. This worked for me to solve this issue.
You may try to specify the full path instead of ./path/to/file
Try to make a new file. click "save as" and make a new name. Run again your code. it worked well to me :)
Although the solution was already given, but for the sake of documentation I will leave my situation here:
I ran into the same problem and couldn't figure out why. It seems that my excel file had closed with an error or something similar. I had to open the excel file, and save it again. When I ran R, everything worked smoothly.
The issue was that there was hidden files inside my working directory. I copied them to outside and exclude all directories. Now it works when I run the code.
In my case the xlsx was created using Excel 2007, which caused this issue. Xlsx files from newer Excel versions work.
In my case the file was not visible in the directory although I had deleted it. I had to search for the file using a software called "Everyting" and I deleted it. After that it worked.
For me, I was downloading a file from Google Drive into a tempfile with extension .xlsx... Realised the file in Google Drive was .xls so I changed it to that and it worked. Kinda rare situation though.
I got the same error message.
In my case the line that worked properly specified the sheet by a string (copied from excel). Suddenly, it did not work anymore (with the mentioned error message). I tried several things explained here. Ended up specifying the sheet by its number in the excel file - worked!
read_xlsx("table.xlsx", sheet="name_of_sheet") # suddently corrupt
read_xlsx("table.xlsx", sheet=4) # works
Why? No update of the package or something. I dislike to have to use a less specific line.
UPDATE: Restarting the R session made the initial line work again (although, I HAD checked the wd before...)
I am trying to load in .nc files into Igor using the following line
Execute/Q "Load_NetCDF/i/q/t/z/s"
I have the Load_NetCDF installed and have used it a lot - it definitely works and works for similar files. I think the difference is that these files contain a couple of multiple dimension waves. Using Load_NetCDF in this way seems to be producing some odd looking results which do not match the content if I look at the same file another way (i.e. looking at the variables individually in MATLAB's ncbrowser).
I am seeing a couple of errors in the Igor command line and have ensured that they occur on the Load_Netcdf line of my code as shown above. Here are the error messages I get:
I've been hunting around for help info on the Load_NetCDF external function but without success. Does anyone know the cause of this problem or a good line of attack to try debugging it?
Are you using the XOP from this page to load the netcdf data?
It states that it does not support 2D waves. I don't know any other XOP to load netcdf data.
The promised error messages in your post are not visible.
What netcdf files are these? Classic or the new format? The new format is based on HDF5 and can, according to this post be read by the HDF5 browser in Igor.