awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
365 stars 78 forks source link

Error in zip_internal when using openxlsx #478

Closed juve0811 closed 5 years ago

juve0811 commented 5 years ago

0

Received this error message from R when using openxlsx package, not sure where to look.

Error in zip_internal(zipfile, files, recurse, compression_level, append = FALSE, : Some files do not exist

Does anyone have any suggestions? thanks.

The code is simple:

library(openxlsx) df1 <- cars write.xlsx(df1, file = 'cars.xlsx')

willemvdb42 commented 5 years ago

I have the same problem. Here is another reprex:

library(openxlsx)

testDf <- data.frame(a = 1:3, b = 3:1, c = letters[1:3], stringsAsFactors = FALSE)
wb <- createWorkbook()
addWorksheet(wb, "test")
writeData(wb, "test", testDf)
saveWorkbook(wb, "test.xlsx")

This generates 1 message and 1 error:

Note: zip::zip() is deprecated, please use zip::zipr() instead Error in zip_internal(zipfile, files, recurse, compression_level, append = FALSE, : Some files do not exist

I'm using opexlsx_4.1.1

juve0811 commented 5 years ago

Hi willemvdb42

Have you changed the windows environment variables recently? I was testing something else, and my script stop working, only the write.xlsx and saveWorkbook functions from "open.xlsx" package.

willemvdb42 commented 5 years ago

Yes, in fact I did change some of those recently. Which ones are you referring to specifically?

juve0811 commented 5 years ago

I don't remember now, trying to recover them since last week.

Seem like that is the root cause for our problem.

willemvdb42 commented 5 years ago

The error resolves itself if you add a TMP environment variable. As I suspected this is because the saveWorkbook function uses the function tempdir which creates a temporary directory and uses the TMP variable (among a list of other options) to do this (see documentation for more info).

The relevant lines of code are on line 223 here. Note that tempdir is not called directly, but through the function tempfile which uses tempdir() as default value for its tmpdir argument.

juve0811 commented 5 years ago

Hi

I added a TMP environment variable (C:\Windows\Temp) in the list, and the return value from tempdir as well, still showing "Some files do not exist".

willemvdb42 commented 5 years ago

Did you restart your R session before you tried? You can check your environment variables like this: Sys.getenv("TMP").

juve0811 commented 5 years ago

Did you restart your R session before you tried? You can check your environment variables like this: Sys.getenv("TMP").

fixed with help from IT, reset the work directory from cmd. Thank you for your help.