使用包openxlsx保存xlsx工作簿时出错

时间:2014-04-29 14:21:01

标签: r

我正在浏览R Statistics中openxlsx包中的插图示例,但我无法保存工作簿,我无法弄清楚原因。下面的代码是插图中的一个修改示例,只是为了简单起见。

setwd("c:/users/kenneth/documents/r/2014-04-29_openxlsx")
require(openxlsx)
require(ggplot2)
wb <- createWorkbook()
addWorksheet(wb, sheetName = "Motor Trend Car Road Tests", gridLines = FALSE)
addWorksheet(wb, sheetName = "Iris")
addWorksheet(wb, sheetName = "Conditional Formatting")
saveWorkbook(wb=wb, file="basics.xlsx", overwrite=TRUE) ## save to working directory

我得到的错误信息是:

Warning message:
running command '"zip" -r1 "c:/users/kenneth/documents/r/2014-04-29_openxlsx/basics.xlsx" "[Content_Types].xml" "_rels" "docProps" "docProps/app.xml" "docProps/core.xml" "xl" "xl/_rels" "xl/_rels/workbook.xml.rels" "xl/charts" "xl/drawings" "xl/drawings/_rels" "xl/printerSettings" "xl/printerSettings/printerSettings1.bin" "xl/printerSettings/printerSettings2.bin" "xl/printerSettings/printerSettings3.bin" "xl/styles.xml" "xl/tables" "xl/tables/_rels" "xl/theme" "xl/theme/theme1.xml" "xl/workbook.xml" "xl/worksheets" "xl/worksheets/_rels" "xl/worksheets/_rels/sheet1.xml.rels" "xl/worksheets/_rels/sheet2.xml.rels" "xl/worksheets/_rels/sheet3.xml.rels" "xl/worksheets/sheet1.xml" "xl/worksheets/sheet2.xml" "xl/worksheets/sheet3.xml" ' had status 127 

这是我的sessioninfo:

R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252   
[3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C                   
[5] LC_TIME=Danish_Denmark.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.9.3.1 openxlsx_1.0.3 

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 digest_0.6.4     grid_3.1.0       gtable_0.1.2    
 [5] MASS_7.3-31      munsell_0.4.2    plyr_1.8.1       proto_0.3-10    
 [9] Rcpp_0.11.1      reshape2_1.4     scales_0.2.4     stringr_0.6.2   
[13] tools_3.1.0   

我已更新到最新版本的R,devtools和Rtools。

1 个答案:

答案 0 :(得分:5)

我认为这里的问题是R找不到Rtools附带的zip应用程序。

您可以使用命令

检查Rtools bin目录是否在R的系统PATH中
shell("PATH")

输出应该看起来像这样(取决于你安装Rtools的位置):

PATH=c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;C:\Windows\system32;C:\... etc

如果Rtools \ bin目录没有出现在字符串中的任何位置,请将其添加进去。

可在此处找到编辑系统路径的说明:
http://www.java.com/en/download/help/path.xml&#34)

如果这不起作用,请给我发电子邮件,我会帮助你(电子邮件在插图中)