20

I was trying to write a xlsx file with write.xlsx and I get this error:

Error: zipping up workbook failed. Please make sure Rtools is installed or a zip application is available to R.
     Try installr::install.rtools() on Windows.

package ‘Rtools’ is not available (for R version 3.1.2) 

What should I do now to fix this?

EDIT: I install Rtools:

>installr::install.rtools()

No need to install Rtools - You've got the relevant version of Rtools installed

but still I get that error after write.xlsx

Scarabee
  • 5,437
  • 5
  • 29
  • 55
user3806649
  • 1,257
  • 2
  • 18
  • 42

4 Answers4

35

You should check the R_ZIPCMD system variable:

Sys.getenv("R_ZIPCMD", "zip")   

The default value: "zip". But it can happen that you have to set the environment variable. If you know exactly the location, you can set it:

Sys.setenv(R_ZIPCMD= "C:/SOMETHING_PATH/Rtools/bin/zip")   

I had the same problem, but setting the R_ZIPCMD solved it.

rmuc8
  • 2,869
  • 7
  • 27
  • 36
user2408209
  • 351
  • 3
  • 2
  • 6
    Is there a way to do this permanently? It is annoying to have to do this every time I run a new script in a new session. – Brian D Mar 09 '16 at 20:28
  • 2
    For a 'permanent` solution, Plunk this in your .Rprofile: `if(devtools::find_rtools()) Sys.setenv(R_ZIPCMD= file.path(devtools:::get_rtools_path(),"zip"))`. [This answer](http://stackoverflow.com/a/39901895/1519199) has more about the why the .Rprofie is not perfect, as does `?startup` – Jthorpe Apr 11 '17 at 19:49
  • Or put it in your Windows User Environmental Variables (or however it is called in foreign languages, search the Control Panel) – MS Berends May 15 '18 at 09:00
9

Install Rtools (for windows) from this location http://cran.r-project.org/bin/windows/Rtools/ Download the one compatible with your current version of R. While installing check the box for changing the path variable or add "c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;" to path variable afterwards. Start new R session...that works with me..hope this helps..

Aniket
  • 91
  • 1
  • 4
    great answer. it might help to clarify this a little: In Win 7, Go to Control Panel > System > Advanced system settings > Environment variables... then under System variables, find Path, Edit... add to the end ";C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin" restart RStudio and go. – Brian D Mar 09 '16 at 21:01
5

Try that before write.xlsx:

detach(package:openxlsx)

library(xlsx)
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Tayeb
  • 51
  • 1
  • 2
0

On my Linux machine, I once got this error when writing a file over the Excel row limit (1,048,576). It was unable to create the file, so produced this message.

If this is your issue, you may need to reshape or truncate your data to have fewer rows. Alternatively, you can try a plain text format which wouldn't have these limits like csv.

sebastian-c
  • 15,057
  • 3
  • 47
  • 93