R openxlsx error using "loadWorkbook": WARNING: simpleWarning in unzip(file, exdir = xmlDir): error 1 in extracting from zip file - r

Attempting to load data from an Excel spreadsheet in R using openxlsx, I get the following error/warning,
WARNING: simpleWarning in unzip(file, exdir = xmlDir): error 1 in extracting from zip file. This is not a zipped file.
Why am I getting this error?

This error is not related to zip-issues. Instead, this is probably a file-lock error. Check to be certain that the workbook in question is not currently open. If so, close it and try again.

Related

Import Excel data into R using openxlsx: Error in file(con, "r") : invalid 'description' argument

I am trying to import the data in my Excel file into R using Openxlsx library:
library(openxlsx)
data <- read.xlsx("datafile.xlsx", sheet = "Sheet1")
However, I get the following error:
Error in file(con, "r") : invalid 'description' argument
In addition: Warning message:
In unzip(xlsxFile, exdir = xmlDir) : error 1 in extracting from zip file
This error is thrown because your Excel file is open.
Save and close the Excel file and try again, it will work.
There's also another possibility: the XLSX file could be password protected. If you delete the password, then this can fix the error.
I think the best way to solve this problem is to reset the pathway of your data source. Please do not include any characters without English in your pathway.
setwd("C:\\Users\\your path way (where you store datafile.xlsx)")
P.S.
Rstudio2021 seem not friendly to non-English user ☺☺☺

error in load () funtion when try to laod .RData format

I need to convert a shapefile (.shp) formate into .RData format. I used the following codes but when I load the RData format file I get error
Code:
# to save .RData format which runs smoothly without error
save(trainData, file = "trainData1.RData")
# to laod the .RData file
load(trainData.RData)
Error Message:
Error in load(trainData.RData) : object 'trainData.RData' not found
Please point out where I'm making mistake!
I kept serching found out that that double inverted commas are needed when loading the .RData
Missing 1 from load(trainData1) was just a paste error that I did while posting.
well this worked,
save(trainData, file = "trainData1")
load("trainData1")

Reading .xls-file in R

I am trying to read a .xls-file into a R dataframe. I've tried:
library(readxl)
dfTest <- readxl::read_excel("file_path/file.xls")
Which gives me:
Error:
filepath: file_path/file.xls
libxls error: Unable to open file
Next I tried:
library(xlsx)
dfTest <- xlsx::read.xlsx("file_path/file.xls",1)
Which results in:
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.io.IOException: block[ 1462 ] already removed - does your POIFS have circular or duplicate block references?
I tried:
library(openxlsx)
dfTest <- openxlsx::read.xlsx("file_path/file.xls")
Which results in:
Error in read.xlsx.default("file_path/file.xls") :
openxlsx can not read .xls or .xlm files!
Last thing that I tried was:
library(RODBC)
conn <- odbcConnectExcel("file_path/file.xls")
Which gives me:
Error in odbcConnectExcel("file_path/file.xls") :
odbcConnectExcel is only usable with 32-bit Windows
Would anyone have an idea how I can read the Excel file? Saving the file as .csv-file and loading it into R works perfectly fine. However, I have a large amount of files that I ultimately want to read and process in a loop. Saving all by hand as .csv is teadious to say the least.
I'm restricted in changing the software installations on the computer I'm working on.
I believe for .xls files read_delim from the readr package should work.
For example:
readr::read_delim("file_path/file.xls",as.is=TRUE)

error loading csv file for R

when i loading csv file for R, i can see the error
but i don't know why this happening
i wrote following code:
setwd("C:\\Users\\규남\\Desktop\\twitter")
library(KoNLP)
useSejongDic()
txt <- readLines(file("test.csv"))
and, this error appear
txt <- readLines(file("test.csv"))
Error in readLines(file("test.csv")) : cannot open the connection
In addition: Warning message:
In readLines(file("test.csv")) :
cannot open file 'test.csv': No such file or directory
why this happening?
file directory is not wrong, and that file in the folder
[enter image description here][1]
please see this
i restart Rstudio, even notebook power
but error appear again
how to i load that csv file?
and why this happening?
here is result useing getwd() function
[1] "C:/Users/규남/Desktop/twitter"
Warning message:
closing unused connection 3 (test.csv)
[1]: http://i.stack.imgur.com/xkFkt.png
When working through these problems I like to use the file.path() function. Look at the documentation, but it makes certain that the separator characters that are used in the string are what R is expecting.
Try:
path <- file.path("C:", "Users", "규남", "Desktop", "twitter")
setwd(path)
library(KoNLP)
useSejongDic()
txt <- readLines(file("test.csv"))

Cannot read data from an xlsx file in RStudio

I have installed the required packages - gdata and ggplot2 and I have installed perl.
library(gdata)
library(ggplot2)
# Read the data from the excel spreadsheet
df = data.frame(read.xls ("AssignmentData.xlsx", sheet = "Data", header = TRUE, perl = "C:\\Strawberry\\perl\\bin\\perl.exe"))
However when I run this I get the following error:
Error in xls2sep(xls, sheet, verbose = verbose, ..., method = method, :
Intermediate file 'C:\Users\CLAIRE~1\AppData\Local\Temp\RtmpE3UYWA\file8983d8e1efc.csv' missing!
In addition: Warning message:
running command '"C:\STRAWB~1\perl\bin\perl.exe" "C:/Users/Claire1992/Documents/R/win-library/3.1/gdata/perl/xls2csv.pl" "AssignmentData.xlsx" "C:\Users\CLAIRE~1\AppData\Local\Temp\RtmpE3UYWA\file8983d8e1efc.csv" "Data"' had status 2
Error in file.exists(tfn) : invalid 'file' argument
Thanks to #Stibu I realised I had to set my work directory. This is the command you use to run in Rstudio; setwd("C/Documents..."). The file path is where the excel file is located.
I had the issue but I solved it differently.
My problem was because my file was saved as Excel (extension .xls) but it was a txt file.
I corrected the file and I did not meet any other error with the R function.

Resources