【问题标题】:How write to file using rapache?如何使用 rapache 写入文件?
【发布时间】:2011-08-06 10:36:47
【问题描述】:

我们正在尝试将一些表数据写入文件,但没有成功。

使用write.csv

这是我们尝试的一些示例代码:

> <%
> 
> X<-c(1:666)
> 
> print(X)
> 
> write.csv(X,"hh")
> 
> %>

这是我们无法计算的 rapache 错误:

RApache Warning/Error!!!

Error in file(file, ifelse(append, "a", "w")) : cannot open the connection
RApache Warning/Error!!!

In addition:
RApache Warning/Error!!!

Warning messages:
RApache Warning/Error!!!

1: In readLines(icon, 1) : incomplete final line found on '/var/www/brew/sampleplan/step1_5.php'
RApache Warning/Error!!!

2: In readLines(icon, 1) : incomplete final line found on '/var/www/brew/sampleplan/step1_5.php'
RApache Warning/Error!!!

3: In readLines(icon, 1) : incomplete final line found on '/var/www/brew/sampleplan/step1_5.php'
RApache Warning/Error!!!

4: In readLines(icon, 1) : incomplete final line found on '/var/www/brew/sampleplan/writefile.php'
RApache Warning/Error!!!

5: In file(file, ifelse(append, "a", "w")) : cannot open file 'hh': Permission denied
RApache Warning/Error!!!

函数 brew 返回 'try-error' 的对象。返回 HTTP 响应码 500。

如果有人可以为我们编写一个简单的示例或纠正我们的代码,那就太棒了。

谢谢,

Yoni & Tsvi。

【问题讨论】:

  • R 无法写入运行 R 的当前工作目录。整理您的权限,然后重试。
  • 请不要交叉发帖!你已经在 RApache 邮件列表上问过同样的问题!
  • 您的来源是否具有我在您的问题中看到的所有大于符号?那可能会把事情搞砸。看起来整个脚本都坏了,而不仅仅是 write.csv。

标签: r rapache


【解决方案1】:

为了让您的生活更轻松,请先让您的代码独立运行,然后再引入 rApache。

您看到的错误意味着write.csv 无法写入您指定的位置。由于写入文件是问题的常见来源,因此您应该添加一些检查和错误处理代码以使事情更加健壮。例如,

  1. 指定绝对路径 (path.expand) 或至少确保您知道当前工作目录的位置 (getwd)。

  2. 检查您正在写入的目录是否存在 (file.exists) 并且您可以写入该目录(file.access,与 mode = 2)。

  3. 将您对write.csv 的调用封装在对trytryCatch 的调用中。

【讨论】:

  • 您好,感谢您的回复。首先,r 代码与 r ENV 完美配合。其次,没有权限问题。整台计算机对每个人开放,以获得 r 和 w 权限。我们这样做是为了避免任何许可问题。 getwd() 命令没有使用 rapache 回复所以我们真的不知道是什么导致了问题)-:
猜你喜欢
  • 2012-01-09
  • 2016-05-03
  • 2019-09-13
  • 1970-01-01
  • 2020-01-29
  • 2011-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多