1

我正在尝试使用write.xlsR 中的函数将一堆数据帧导出到 excel

预期结果:应将所选数据框导出到 R

Error Message: [1] "Does 'python' exist, and is it in the path?"

可重现的代码:

purchase_year <- c(2007,2007,2007,2008,2008,2008,2009,2009,2009,2009,2009)
sold_year <- c(2007,2008,2009,2009,2010,2011,2009,2010,2011,2012,2013)
units <-c(1,4,4,8,3,1,3,1,1,0,2)
df <- data.frame(purchase_year,sold_year,units)


library(dataframes2xls)
  write.xls(df,"C:/WORK/OUTPUT.xls", sh.names = "default", formats = "default",
            t.formats = FALSE,  fnt.metr = "default",
            col.widths = 48, col.names = TRUE, row.names = FALSE,
            to.floats = "default",  python = "python", 
            py.script = "default", sh.return = FALSE)

其他信息:

  1. 我正在使用 32 位 Windows 7 机器
  2. 也安装了 Python 3.2.2
  3. 浏览了 write.xls 的文档
  4. 尽我所能查找这个和其他论坛
  5. 尝试在 python 参数中包含 python 'exe' 的 URL,这也可以工作

由于我将在多个工作表中写出多个工作表,因此 CSV 目前看起来不是一个选项。

感谢大家的帮助,问题已解决

解决方案

  1. 确保安装了正确版本的 Python。dataframes2xls旨在与 Python 2.x 一起使用。我用的是 2.7.5
  2. R 无法访问我系统中的 Python 安装。我尝试了 David Marx 概述的步骤,我在这里引用:尝试转到命令提示符并运行命令 python。如果这返回错误,则需要将 python 可执行文件的路径添加到 PATH 环境变量:computerhope.com/issues/ch000549.htm
4

2 回答 2

0

我测试了你的代码。我虽然在运行 Centos。在我将输出文件名更改为“Output.xls”后它工作正常。似乎是 Windows 问题,或者您没有正确配置 python/R。

于 2013-07-16T14:40:42.270 回答
0

我不知道这个包,但我敢打赌,问题在于它是为 python 2.x 而设计的,而不是为 python 3.x(这是一种略有不同的语言)。尝试安装 python 2.7。您可能需要卸载当前的 python 3.x

于 2013-07-16T14:42:02.370 回答